LeadSquared Interview Questions

On 12th july , I got a chance to sit for the written round of Leadsquared drive.
In 1 hour we have to do 3 java questions.

1st question->Excel sheet problem
                      ex. 1 -> A , 2->B , 26->Z ,27->AA 

 import java.util.*;

public class excel
{
public static void main(String args[])
{
  Scanner s=new Scanner(System.in);
       int r,n=s.nextInt();
  String k=" ";
       while(n>0)
  {
r=n%26;
          if(r==0)
 {
String ch="Z";
            k=k+ch;
n=n/26 -1;
 }
          else
 {
 int ch=r-1+(int)'A';
 char p=(char)ch;
 String h= Character.toString(p);
              k=k.concat(h);    
     n=n/26;
 }
  }
 
  int len=k.length();
  for(int i=len-1;i>=0;i--)
  System.out.print(k.charAt(i));
       // System.out.println(k);  
}
}



2nd Question-> find a number just bigger than the given number, with the same digits combination.
                          example  : 756 -> 765  ,  342-> 423 , 987->"Not possible"


#include<bits/stdc++.h>

using namespace std;

int main()
{
    string k;
    cin>>k;
    int l=k.length();
    int a[l];

    for(int i=0;i<l;i++)
     a[i]=k[i]-'0';

    int lst=a[l-1],fl=0,rem;

    for(int p=l-1;p>=1;p--)
    {
     for(int i=p-1;i>=0;i--)
     {
      if(a[p]>a[i])
       {
          fl=1;
          int tmp=a[i];
          a[i]=a[p];
          a[p]=tmp;
          rem=i+1;
          break;
       }
     }
     if(fl==1) break;
    }


    if(fl==0) cout<<"Not possible"<<endl;
    else
    {
         sort(a+rem,a+l);
        for(int i=0;i<l;i++) cout<<a[i];
        cout<<endl;
    }
    return 0;
}



3rd Question: Parenthesis Balance Checking Problem.
                       {([]{})}-> Balanced , {}() ->Balanced , {(})-> Not Balanced



import java.util.*;

public class balanced_parenthesis
{
public static void main(String arg[])
    {
 Scanner s=new Scanner(System.in);
      String k=s.nextLine();
      int l=k.length(),fl=0;
     
 Stack st = new Stack();
     
      for(int i=0;i<l;i++)
      {
        if(k.charAt(i)=='(' || k.charAt(i)=='{' || k.charAt(i)=='[')
         {
st.push(new Character(k.charAt(i)));
         }
        else if(k.charAt(i)==')' || k.charAt(i)=='}' || k.charAt(i)==']')
        {
          if(st.empty())
          {
              fl=1; break;
          }
 char a = (Character) st.pop();
          if((k.charAt(i)=='(' && a!=')') || (k.charAt(i)=='[' && a!=']') || (k.charAt(i)=='{' && a!='}'))
            {
                fl=1; break;
            }
       }
     }  

if(!st.empty() || fl==1)
System.out.println("Not balanced");
    else
        System.out.println(" balanced ");

}
}


Comments

Popular posts from this blog

Getting Started With MEAN App Development with AngularJs , ExpressJs , NodeJs and MongoDB.

B. Dreamoon and WiFi :calculate no. of ways : recursive solution (branch and bound )

A. Dreamoon and Stairs : minimum steps to reach : recursion solution.