Programmer Interview Questions | Glassdoor.co.in

# Programmer Interview Questions

85,398

programmer interview questions shared by candidates

## Top Interview Questions

Sort: RelevancePopular Date

3 Nov 2017

### Software Developer at WebKul was asked...

8 Apr 2018
 1. pattern question n=1 * *** n=2 * *** * * ***** n=3 * *** * * ***** * * * *******8 Answers#include void main() { int i,j,k,l,m,n; n=2,m=3; for(i=1;i<=n;i++) { for(l=1;l<=i+1;l++) { if(l<=i) { for(j=1;j<=n;j++) { printf(" "); } } if(l==i+1) { for(j=l;j<=n;j++) { printf(" "); } } if(l<=i) { printf("*"); } else if(l==i+1) { for(k=1;k<=m;k++) { printf("*"); } m=m+2; } printf("\n"); } } }wrong value user input#Answer in python n=2 m=3 i=1 while i<=n: j=1 while j<=i+1: if j<=i: k=1 while k<=n: print(" ", end="") k=k+1 if j==i+1: k=j while k<=n: print(" ", end="") k=k+1 if j<=i: print("*") elif j==i+1: k=1 while k<=m: print("*", end="") k=k+1 print() m=m+2 j=j+1 i=i+1Show more responsespublic class MyClass { public static void main(String args[]) { int n=3; for(int j=1;j<=n;j++) { for(int i=0;i<=j;i++) { if(i#Answer in Java public class MyClass { public static void main(String args[]) { int n=3; for(int j=1;j<=n;j++) { for(int i=0;i<=j;i++) { if(iYe code mai n ki value toh pass kra dete bhaio , loop mai pta nhi kya I<,I,l,|,....hai yeYou can try its easy int i,j,a; int n=3; for(a=1;a<=n;a++) { for(i=1;i<=a+1;i++) { for(j=1;j<=2*a+1;j++) { if(i==a+1||j==2) {System.out.print("*");} else{System.out.print(" ");} } System.out.println(); } }n=int(input()) k=1 for i in range(0,n): for j in range(0,i+1): print(" "*n+"*") print(" "*(n-k)+"*"*(2*k+1)) k=k+1

16 Jun 2012
 Puzzle question: A Floating ship contains 1 stone , If I drop that stone in sea,,What will happen with water level??? Is it increase or decrease n why?? 8 Answersafter long discussion... concluded that it will decrease..nothing will happeneven i feel nothing will happen to the level.plz explain the ans.Show more responsesLevel will decreaseYes It will decrease, as per Arcemedes object with same masses upward buoyant force is higher for object which has larger volume area, so when stone is on boat, it increase boat weight and so upward buoyant force is high for boat, but when It is thrown its upward buoyant force is less with compare to when it is on boat, and upward buoyant force of boat also decreases because stone is thrown, so ultimately upward buoyant force decrease than means decrease in water level, hope it will help :)I think it will decrease as when the stone is on the boat the volume of water it displaces is more than when it is thrown into the sea. as more volume of water is displaced the more water level goes up we can say that water level will be higher when the stone is on the boat.The amount of water displaced is equal to the mass of the object immersed. Since the net mass of objects in water is the same, the same amount of water needs to be displaced. Hence no change in the water level.It solely depends upon the density of stone. If density of stone is higher than boat material then it will increase the water level .. Otherwise decrease

### Junior Programmer at Ubisoft was asked...

14 Jul 2017
 How to check if a number is divisible by 16 without using operator / or % ?8 Answersshould do using bit-wise operatorsI will run a loop that'll subtract 16 from the number. If result is zero than it is divisible else if it goes less than zero than its is not.Bit wise right shift four times, if integer then divisible.Show more responsesfor(int i=0;in) { break; } //number is not divisible by 16 //which will be decided by the flag } }Sorry for that incompleted answer ! I want to say that simply use a loop upto n and multiply each number with 16 and store in a variable and then go for a check if it is matched by n or not. If matched then flag==true else break;If a number is divisible by 2^n, do bitwise right shift n times and then bitwise left shift n times to get back the same number.if(16>>4 == 0 ) True; else FalseThe above condition should be 1 instead of 0. if(16>>4 == 1 ) True; else False

25 Sep 2018

### Senior Software Engineer at Virtusa was asked...

19 Sep 2010
 if there are 6 people in a team, how many handshakes will be there8 Answers15There will be 30 hand shakes. In total we have 6 people, so it will be 6 * (6-1) (i.e 1 person will shake hands with 5 people)15 A | B | C| D | E | F | A will perform 5 B will perform 4 C will perform 3 D will perform 2 E will perform 1 F ultimately hand shakes with everyoneShow more responses6c2==6!/(2!*4!)=15lets consider A,B,c,d,e,f so a shakes hand with the other 5 ..b with oter 4 and so on so at last 5+4+3+2+1=1515 people handshakes at a time you have given 6 person first of all the peoples is arranged in row 6 number people have an 5 option for handshakes after that 6 number person out then total number of people 5 again....again....same procedure apply.......Each one will shake hand 5 times, 6x5 -> 30 times6c2= 15

### Software Developer at Zoho was asked...

17 Feb 2019
 Short coding : 1. They gave an array A with N elements we need to find if addition of two elements in the array will be the element K Ex: I/P: a={7,3,2,6,4,} K=10; Op:7+3=10 6+4=10 2. Two sorted array a[],b[] will be given we need to merge the array without temporary array. 3. An array arr[] with elements are given we need to sort the odd number in descending on left side and the even numbers in ascending on the right side of the array Ex: I/P: arr={7,4,3,5,2} O/P:7 5 3 2 48 AnswersHave you mail for 3rd round?Is 3rd round over?I am not completed the 2nd round successfully so I did not know about further round questions..Show more responsesOkay Bro. I was in the same batch. In 2nd Round, I have completed 5 questions. Still I didn't get result.pls tell about...all round conducst same day or different day1st round conducted on 9th Feb 2019 at 10:00 am and the result will be mailed me on 12th Feb and the second round conducted on 16th FebSame day I also attended. Cleared 5 questions in 2nd Round. Still Didn't get the result.

### Software Engineer II at Amazon was asked...

19 Jun 2012
 Given an large list of unsorted numbers, find the smallest number. You can access the list only 3 numbers at a time, and keep moving forward 1 number at a time.6 AnswersOtherwise called the sliding window problemUse the selection sort and after the pass stop the iterating. Time complexity will be O(N) & only one swap.Use the selection sort and after the first pass stop the iterating. Time complexity will be O(N) & only one swap.Show more responsesDid they asked to write the code of the solution? or just pseudo code.And did they added any constraints? Otherwise this is pretty straight forward problem using Insertion sort.You can access the list only 3 numbers at a time: It tells we can read three numbers one after other in N/3 Iterations. So Time complexity will be O(N/3)This is sliding window problem and priority queue DS can be used to solve this.

### Assistant Software Engineer at Nucleus Software Exports was asked...

16 Apr 2016
 Q1. Print the 1st and 100th element of Fibonacci series together, 2nd and 99th element and so on. Q2. Print the following pattern 1 2 4 3 6 9 4 8 12 16 5 10 15 20 25. (Condition was using one for loop)8 AnswersSince both the question required 2 for loops. A1. I created a function fibo() that returns finbonacci nth element using recursion . And run a for loop from 1 to 100 and print the fibo(i) and fibo(100-i) [i running from 1 to 100]. A2. I created a recursive call to a function that acted as the outer loop and a base condition to exit. and in the else part do the printing using a single for loop.For question 2: //here i = 5 void print_sequence(int i) { int num = 1; int count = 0; for(;num= num) { count = 0; num++; cout<For question 2: //here i = 5 void print_sequence(int i) { int num = 1; int count = 0; for(;num= num) { cout=num) { count = 0; num++; cout<Show more responses#include using namespace std; int main() { int j=1; for(int i=1; i<=10; ){ cout << j*i << " "; if(j == i){ i++; j=0; cout << endl; } j++; } return 0; }#include #include #include #include #include #include using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int i; cin >> i; int j=1; for(int k=1;kj) { cout << endl; j++; k=0; continue;} else cout << j*k << " "; } }For the fibonacci, the best way wud be to create an array of fibonacci numbers from 1-100 using dp which uses just one for loop. and then print sumultaneously the following asked numbers.#include using namespace std; main() { int i,j; for(i=1,j=1;i<=5;) { cout<import java.util.Scanner; import static java.lang.System.out; class PA{ public static void main(String...args){ int a=1,i=1,j=1; Scanner sc=new Scanner(System.in); int n=sc.nextInt(); while(a!=0){ out.print(i+" "); if(i==(j*j)){ out.println(""); j++; i=j; } else{ i=i+j; } a++; if(i==(n*n)) {out.print(i); break;} } } }

12 Sep 2015