Open In App

Smartprix Interview Experience | Set 4 (On-Campus)

Improve
Improve
Like Article
Like
Save
Share
Report

Recently Smartprix conducted a pool placement drive.
There were two rounds:
1. Logical / Technical ability Test
2. Coding Round

First Round:
First round was divided in two tests,
1. Logical Ability Test: The test consists of 20 questions in 30 minutes, there was negative marking 3marks rewarded for each correct and 1 mark deducted for each wrong answer. Most of the questions were based on pattern matching. Apart from that, questions from series, missing term and blood relations were also there. All over there were intermediate level question.

2. Technical MCQ Test: This test consisted of 10 questions in 30 minutes. Questions were from c++ and java. Some were output based while some were on logic testing. Questions were of middle level.
Out of around 650 students 63 students were selected for next round – Coding round.

Second Round:
This round had 2 coding questions which should be done in 3 hours .The level of questions were quite decent. Basically questions were based on practical problems that you are most likely to face at work.
Question1. Key Stroke: Write a program to simulate a keyboard with given Keys and their operation .Type of keys to simulate were: Alphanumeric space: print it as it is and shift cursor.
@ = toggles caps lock on if off and vice versa, initially it is off.
# = inserts a new line at cursor position and shift cursor.
/ = deletes one character at left and points cursor at that position.
? = works as down arrow if cursor is at last line nothing changes.
^ = works as up arrow if cursor is at first line nothing changes.
This question was of 210 marks.

Examples:

Input :  asdf#q#pqr^^23
Output :asdf23f
           q 
           pqr




# Python code
string=input()
caps=0
result=[]
j=0
i=0
pos=0
while (i<len(string)):
    if string[i]==&#039;@':
        if caps==1:
            caps=0
        else :
            caps=1
        i=i+1
    elif string[i]==&#039;#':
    #    print (result)
        result.insert(j,&#039;\n')
    #    print(result)
        j=j+1
        i=i+1
    elif string[i]==&#039;':
        i=i+1
        j=j+1
    elif string[i]=='/':
        j=j-1
        result=result[:j]+result[j+1:]
        i=i+1
    elif string[i]=='^':
        count=0
        p_j=j
        pos=0
        while (string[i]=='^'):
            count=count+1
            i=i+1
        j=j-1
        count=count+1
        check=1000000
        while(count and j>=0):
            if(result[j]=='\n'):
                if(p_j-j-1=check :
            while(check):
                  
                j=j+1;
                check=check-1
            j=j+1
        else :
            while(result[j]!='\n'):
                j=j+1;
            j=j-1
                  
    elif string[i]=='?':
        count=0
        p_j=j
        while (string[i]=='?'):
            count=count+1
            i=i+1
        j=j-1
          
        if count==1 :
              
            while(count>0):
                  
                if result[j]=='\n':
                    count=count-1
                      
                j=j+1
              
        elif count>1 :
          
            while(check):
                j=j+1;
                check=check-1
            j=j+1
          
    else:
        if (caps==1) and  string[i].islower():
            result.insert( j,string[i].upper())
        else :
            result.insert( j,string[i])
        j=j+1
        i=i+1
print (''.join(result))


This question was of 250 marks.
Question2. This program was something like executing commands of assembly language in your program. Set of commands given were:
1. ECHO 1: prints the number. Eg. ECHO 1 prints 1
2. Exit: exits the program.
3. SET a 0: assign variable a value 0.
4. ADD 2 3 z: this means z = 2+3 assign sum of first two values to third one.
5. GOTO and LABEL: works as label and Goto defined in c language but label can be before or after goto
6. IF and END: If IF condition is true then statements between IF and END commands get executed otherwise not. Eg. IF a 10 statement1 statement2 END i.e., if a=10.
7. CONTINUE: works as defined in c language.
Variable names will only be alphabetic [a-z] and default values of variables is 0 no need to define or set before use.
Examples:

Input        Output
   SET a 0       1
   LABEL 100     2
   ADD a 1 a     3
   ECHO a        4
   IF a 5        5
   EXIT
   END    
   GOTO 100 




#Python code 
from sys import stdin
newdict = {}
dict={}
i=0
for line in stdin:
    list1=line.split(" ")
    list1[-1] = list1[-1].strip()
    newdict[i]=list1
    i=i+1
key=0
j=0
key_if=[]
label={}
while (key in newdict):
#    print (key)
    if newdict[key][0]=="SET":
        if not newdict[key][2].isalpha():
            dict[newdict[key][1]]= int(newdict[key][2])
        else:
            dict[newdict[key][1]]= int(dict[newdict[key][2]])
        key=key+1
    elif newdict[key][0]=="ADD":
        #print(key)
        if not newdict[key][1].isalpha() and not newdict[key][2].isalpha():
            dict[newdict[key][3]]=int(newdict[key][1])+int(newdict[key][2])
        elif not newdict[key][1].isalpha():
            dict[newdict[key][3]]=int(newdict[key][1])+int(dict[newdict[key][2]])
        elif not newdict[key][2].isalpha():
            dict[newdict[key][3]]=int(dict[newdict[key][1]])+int(newdict[key][2])
        elif newdict[key][1] in dict and newdict[key][2] in dict :
            dict[newdict[key][3]]=dict[newdict[key][1]]+dict[newdict[key][2]]
        key=key+1
    elif newdict[key][0]=="ECHO":
        if newdict[key][1].isalpha():
            print (dict[newdict[key][1]])
        else :
             print (int(newdict[key][1]))
        key=key+1
    elif newdict[key][0]=="EXIT":
        break;
    elif newdict[key][0]=="IF" :
        key_if=key_if+[key+1]
        if newdict[key][1] in dict and newdict[key][2] in dict :
            if(dict[newdict[key][1]]==int(dict[newdict[key][2]])):
                key=key+1
        elif(dict[newdict[key][1]]==int(newdict[key][2])):
             key=key+1;
        elif  dict[newdict[key][1]]!=int(newdict[key][2])  :
                while (newdict[key][0]!="END"):
                    key=key+1
                key=key+1
                key_if.pop()
        elif newdict[key][2].isalpha() and dict[newdict[key][1]]!=dict[newdict[key][2]]:
                while (newdict[key][0]!="END"):
                    key=key+1
                key=key+1
                key_if.pop()
    elif newdict[key][0]=="CONTINUE" :
        key=key_if[-1]
    elif newdict[key][0]=="LABEL" :
        label[newdict[key][1]]=key
        key=key+1
    #    print (key)
    elif newdict[key][0]=="GOTO":
        #print(label[newdict[key][1]])
        key=label[newdict[key][1]]




Last Updated : 01 Oct, 2017
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads