Software Developer Interview Questions
- 0of 0 votes
AnswersJack love playing games, Gluttonous snake( an old game in Nokia era) is one of his favorite. However, after playing gluttonous snake so many times, he finally got bored with the game, so he changed the rules:
- mirrorme March 12, 2016 in United States
Rule 1: Write a code to find the Max sum path in a grid (2-D array), with dimension with n rows and m column (1<=n,m<=500)
Rule 2: In the 2D Array, each cell (elements) contains a value v in the array is from (-1<=v<=99999)
Rule 3. You can start from any position of the leftest column (border) of the array to the rightest(border) column of the array to calculate the Max Sum path.
Rule 4. You can move up, right, down, and CAN'T move left, and can visit each element only one time.
Rule 5.If the element is -1, it means the path is blocked, and you can't go through the path (calculate it in the sum), you have to choose other path to calculate the sum.
For example, if a 4*4 array grid
{{-1,3,2,1}
{2,-1,2,4}
{2,2,-1,3}
{4,2,1,2}};
The max sum path is : (from grid[4][0])
4-->up-->2-->left-->2-->down-->2-->left-->
1-->left-->2-->up-->3-->up-->4-->up-->1
and the sum is 4+2+2+2+1+2+3+4+1 =21
Thank you
Here is my code, I am new in Java and there is still lots of improvements
import java.util.*;
public class MainClass {
public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner rowDimension = new Scanner(System.in);
System.out.print("Enter the number of rows: ");
int firstInput = rowDimension.nextInt();
@SuppressWarnings("resource")
Scanner columnDimension = new Scanner(System.in);
System.out.print("Enter the number of columns: ");
int secondInput = columnDimension.nextInt();
//Input two number to generate 2D Array
Integer [][] array = new Integer[firstInput][secondInput];
//The purpose of the array is check the wall (cell value = -1)
boolean [][] visited = new boolean[firstInput][secondInput];
//Use Math.random() to generate the cell of the array
int[][] randomTable = new int[firstInput][secondInput];
for (int row = 0; row < firstInput; row++) {
for (int column = 0; column < secondInput; column++) {
// multiply by 1000000 to get a number between 0 and 99999
randomTable[row][column] = (int)(Math.random() * 1000000 -1);
System.out.print(randomTable[row][column] + " ");
}
System.out.println();
}
//Start form the left-down location of grid
int i = firstInput-1, j = 0;
visited[i][j] = true;
double sum = array[i][j];
while(true)
{
int max = -1;
int maxi = 0, maxj = 0;
//Case1 : choose path: UP
if(i-1 >= 0 && i-1<= firstInput-1 && j>=0 && j<= secondInput-1 && array[i-1][j] != null && array[i-1][j]>max && !visited[i-1][j])
{
max = array[i-1][j];
maxi = i-1;
maxj = j;
}
//Case2 : choose path: Down
if(i+1 >= 0 && i+1<= firstInput-1 && j>=0 && j<= secondInput-1 &&array[i+1][j] != null && array[i+1][j]>max && !visited[i+1][j])
{
max = array[i+1][j];
maxi = i+1;
maxj = j;
}
//Case3 : choose path: Right
if(i >= 0 && i<= firstInput-1 && j+1>=0 && j+1<= secondInput-1 && array[i][j+1] != null && array[i][j+1]>max && !visited[i][j+1])
{
max = array[i][j+1];
maxi = i;
maxj = j+1;
}
i = maxi;
j = maxj;
visited[i][j] = true;
sum += max;
//To the destination : Right-Up location of the grid
if(i == 0 && j == secondInput-1)
break;
}
System.out.println(sum);
}
}| Report Duplicate | Flag | PURGE
TATA Consultancy Services Software Developer Java - 0of 0 votes
AnswersA flipping rule is given as a follows: Consider a series of positive integer. Take three numbers in the series next to each other. On applying the flipping rule to these numbers, the right most number will go to the left most number position and the other two numbers will move one position to the right at the same time. The rule can be applied to any three numbers present next to each in the series and can be applied as many times as needed.
- Info.Dubey March 03, 2016 in India
Given n as the number of element in the original series, elements of the original series and a target series of a numbers, figures out if the target series can be created by flipping numbers of the original number and output the word “POSSIBLE” followed by the number of times the flipping rule has to be applied. In case, the target series cannot be formed, output the word “IMPOSSIBLE”.
Example :
For a series with 4 elements in it, 1 3 4 2 a new series = 4 3 2 1 can be formed by applying flipping rule as follows, From the table below we can say the output is POSSIBLE 3.
Steps
Series
The three Numbers Flipped
Resultant Series
1
1 3 4 2
1 3 4
4 1 3 2
2
4 1 3 2
1 3 2
4 2 1 3
3
4 2 1 3
2 1 3
4 3 2 1
Example input
Example OutPut
4 1 3 4 2 4 3 2 1
POSSIBLE 3
6 1 2 3 4 5 6 6 5 4 3 2 1
IMPOSSIBLE| Report Duplicate | Flag | PURGE
Infosys Software Developer C++ - 0of 0 votes
AnswersYou are given an array of variable length, which contains only following integers: -1, 0, 1.
- kishoredbn March 01, 2016 in United States
Example A[] = {0, 1, 0, 1, 1, -1, 1}
You are also given an integer S.
Write a program with O(n) time that can find out the length of the largest sub-array which sums up to S.
Example, if S = 2, then the length of the largest sub-array in the above array is 6.
If there is no such sub-array that can sum up to S, then output 0.| Report Duplicate | Flag | PURGE
Galatea Associates Software Developer Algorithm - 1of 1 vote
Answerswhich number most unlikely belong to following set of number 9 23 46 75 116
- akash.umang February 27, 2016 in India| Report Duplicate | Flag | PURGE
Adobe Software Developer Puzzle - 0of 0 votes
Answersuse case where only namespaces can only be used in c++
- jkl February 23, 2016 in India| Report Duplicate | Flag | PURGE
Siemens Software Developer - 0of 0 votes
AnswersWrite a program to balance the binary search tree ?
- mithleshtechno February 21, 2016 in United States
with explanation and preferred
C language..| Report Duplicate | Flag | PURGE
TATA Consultancy Services Software Developer - 0of 0 votes
AnswersBinary search inorder traversal asked by Amazon
- Info.Dubey February 20, 2016 in India
struct Node
{
int data;
Node *right.*left,*random
}
Tree should be in-order traversal and random node should keep the in-order transversal path.| Report Duplicate | Flag | PURGE
Amazon Software Developer Data Structures - 0of 0 votes
AnswersAmazon interviewer has told to made a program which print number increment or decrement fashion depend on the user input.
- Info.Dubey February 20, 2016 in India
suppose if user enter "ID" where "I" stands for increment number and "D" stands for decremental number and produced output should be 231. they have given three condition first condition Number should be belongs from 1 to 9.
second condition number should not be duplicate
third number should be least number.
example:
User input "ID"
Number should be 231
if User Input "IDDI"
then output should be 45312
if user input "IID" then output should be 2341| Report Duplicate | Flag | PURGE
Amazon Software Developer - 2of 2 votes
AnswersDefine a function that can detect whether the characters of a string can be shuffled without repeating same characters as one other's neighbors. E.g. :
- fahmida.hamid February 11, 2016 in United States
apple >> alpep, so valid
a >> a, valid
aa >> aa, invalid/impossible
aab >> aba, valid
aaaabbcc >> acabacab, valid
etc.
You do not have to find one representation, just have to detect if it is possible or not!| Report Duplicate | Flag | PURGE
Google Software Developer Algorithm - 3of 3 votes
AnswersCheck if an integer array is arithmetic sequence.
- PS February 08, 2016 in United States
Example: 1, 2, 3, 4, 5, 6, 7, 8 => true
1, 3, 5, 7, 9 => true
Array may not be sorted.| Report Duplicate | Flag | PURGE
Amazon Software Developer Algorithm - 0of 0 votes
AnswerAn Integer array is given,
- chjit99 February 08, 2016 in India
Find the combination of number in the array which satisfies the equation: a to the power b= c.
A number should not be repeated in multiple combination.
1. a and b are adjacent no. in the array.c can be any where in the array.
2.No other array or data structure can be used. However modification of current array is possible.
Define a function which will take array as input and generate a output array (a modification of input array).
Example: Input array: 1 2 3 8 5
out put: 2 3 8 0 0| Report Duplicate | Flag | PURGE
xyz Software Developer - 0of 0 votes
AnswersGiven a 2D array of digits, try to find the occurrence of a given 2D pattern of digits. For example, consider the following 2D matrix:
- kohansey February 04, 2016 in United States
7283455864
6731158619
8988242643
3839505324
9509505813
3843845384
6473530293
7053106601
0834282956
4607924137
Assume we need to look for the following 2D pattern:
950
384
353| Report Duplicate | Flag | PURGE
Amazon Software Developer Matrix - 0of 0 votes
AnswersHi.For the online assessment test - Debugging , which programming languages code snippet I can expect?Thank you !
- Priti January 23, 2016 in United States| Report Duplicate | Flag | PURGE
Amazon Software Developer Debugging - 0of 0 votes
Answersconvert a number m to n with minimum operations. The operations allowed were -1 and *2.
- Rahul Sharma January 13, 2016 in United States
For Eg : 4 and 6. Answer is 2.
1st operation : -1 -> 4-1 = 3.
2nd operation : * -> 3 * 2 =6.| Report Duplicate | Flag | PURGE
Software Developer Algorithm - 0of 2 votes
AnswersHow many Fibonacci numbers exists less than a given number n.Can you find a function in terms of n , to get the number of fibonacci number less than n.
- Rahul Sharma January 13, 2016 in United States
Example : n = 6
Answer: 6 as (0, 1, 1, 2, 3, 5)| Report Duplicate | Flag | PURGE
Google Software Developer Algorithm - 0of 0 votes
AnswerA delivery boy wants to deliver some items on his way from office to home. You need to find the optimized path he should take from office to home and deliver all his deliveries on his way.
- mirinda January 09, 2016 in India
It is 101 X 101 grid. Office, home , delivery points are represented via coordinated (x,y) where 0 <= x <= 100, 0 <= y <= 100.
distance between two points (x1, y1) and (x2,y2) is computed as |x1 - x2| + |y1 - y2|
You need to find the optimized path from office to home covering all delivery locations and return the optimized path length as output.
You will be given the input in the 2 lines
first line - N (no. of delivery locations)
second line - (x,y) coordinates of office, followed by home, followed by all N delivery locations.
3
0 0 100 100 20 30 50 50 70 70
output: The length of the optimized path taken.
For above input, the output is 200| Report Duplicate | Flag | PURGE
Samsung Software Developer Problem Solving - 0of 0 votes
AnswersSuppose you have ten million data in a array where each data should be 15 in length. Some of the data length changed somehow. How do you find out which data are distorted.
- pcbabu January 05, 2016 in United States| Report Duplicate | Flag | PURGE
Software Developer - 0of 0 votes
AnswersCounting the number of digits before and after the decimal point without using string ( using double data type).
- Rohit Hajare December 29, 2015 in India| Report Duplicate | Flag | PURGE
Software Developer C - 0of 0 votes
Answers
- Desi Joe December 22, 2015 in United Statesinterface RangeContainerFactory { /** * builds an immutable container optimized for range queries. * Data is expected to be 32k items or less. * The position in the “data” array represents the “id” for that instance * in question. For the “PayrollResult” example before, the “id” might be * the worker’s employee number, the data value is the corresponding * net pay. E.g, data[5]=2000 means that employee #6 has net pay of 2000. */ RangeContainer createContainer(long[] data) } /** * a specialized container of records optimized for efficient range queries * on an attribute of the data. */ interface RangeContainer { /** * @return the Ids of all instances found in the container that * have data value between fromValue and toValue with optional * inclusivity. The ids should be returned in ascending order when retrieved * using nextId(). */ Ids findIdsInRange(longfromValue, long toValue, boolean fromInclusive, boolean toInclusive) } /** * an iterator of Ids */ interface Ids { /** * return the next id in sequence, -1 if at end of data. * The ids should be in sorted order (from lower to higher) to facilitate * the query distribution into multiple containers. */ static final shortEND_OF_IDS = -1 short nextId() } Validation: Your implementation should pass the following simple JUnit test before you start tuning for performance with volume data: public class RangeQueryBasicTest { private RangeContainer rc @Before public void setUp(){ RangeContainerFactory rf = new YourRangeContainerFactory() rc = rf.createContainer(new long[]{10,12,17,21,2,15,16}) } @Test public void runARangeQuery(){ Ids ids = rc.findIdsInRange(14, 17, true, true) assertEquals(2, ids.nextId()) assertEquals(5, ids.nextId()) assertEquals(6, ids.nextId()) assertEquals(Ids.END_OF_IDS, ids.nextId()) ids = rc.findIdsInRange(14, 17, true, false) assertEquals(5, ids.nextId()) assertEquals(6, ids.nextId()) assertEquals(Ids.END_OF_IDS, ids.nextId()) ids = rc.findIdsInRange(20, Long.MAX_VALUE, false, true) assertEquals(3, ids.nextId()) assertEquals(Ids.END_OF_IDS, ids.nextId()) } } FAQ Can't we just use a B-Tree/ NavigableMap/HashTable/BinarySearch/Lucene... Sure, if you want. But there are a number of things we'd like to achieve: ● The container will be in memory and will need to hold lots of data, so we'd like it to be as space efficient as possible, but not to the extent where speed is significantly compromised. Speed is king, memory/disk can be purchased. ● Since we hate collecting garbage, we need to be careful about memory allocation during a query, as my grandmother told me, "allocate not, gc not". ● Code should be clear and understandable. ● The rough order of trade off to consider for this case is: search performance, efficient usage of memory, simplicity and maintainability of the code These objectives are often at odds - we'd like to explore what's possible.
| Report Duplicate | Flag | PURGE
unknown Software Developer Algorithm - 0of 0 votes
AnswersTwo files are there file1.txt, file2.txt - both have some random names.
- Rajarathinam Antony December 08, 2015 in India
Like,
file1.txt file2.txt
---------- -----------
Raja Uthaya
Antony Karthi
Christopher Raja
Manickam Antony
Veeramani
Assume file1.txt can have more names(whole database of names), file2.txt has some selected names
You have to display what are all the mismatching items from file1.txt
Need efficient algorithm to do this| Report Duplicate | Flag | PURGE
Honeywell Software Developer Algorithm - 0of 0 votes
AnswersGiven string say ABCGRETCABCG and substring length let us take length as 3, find the count of possible substrings, for example in above string ABC => 2 and BCG => 2 , where CGR and other 3 word length substrings has a count of 1.
- softwaregeek December 08, 2015 in India for Not known| Report Duplicate | Flag | PURGE
Linkedin Software Developer Algorithm - 0of 0 votes
AnswersGiven a set of numbers find if a triplet can form a triangle a+b > c , b+c > a and c+a > b. The result to display all possible combinations of triplets. [ 10 5 3 4 7 1] [5,3,4 ] is one possible triplet and there can be many more.
- softwaregeek December 08, 2015 in India for Not known| Report Duplicate | Flag | PURGE
Linkedin Software Developer Algorithm - -1of 3 votes
AnswersA frog has to cross the river from one end to another end. river has stones in between randomly where frog can jump. frog can't jump into the river. problem is that will frog ever reach other end with following conditions?
- anuprao85 December 01, 2015 in United States for Office
1. frog allow to do same jump as previous jump. or
2. frog allow to jump 1 more as previous jump. or
3. frog allow to jump 1 less as previous jump.
consider river as Boolean Array. Stone is a element in array where value is true .| Report Duplicate | Flag | PURGE
Microsoft Software Developer Data Structures - 0of 0 votes
AnswersArray with distinct elements is given to you. write an API to return max selected ZIG ZAG array length.
- siva.sai.2020 November 23, 2015 in -
Zig Zag array can start with either '<' or '>'. Below two are valid Zig Zag arrays.
a<b>c<d>e<f
x>y<z<l>k
Note: you may need to skip some elements while selecting Max Zig Zag array. But you should not change array order(swapping and sorting not allowed).
-----------
Zig Zag array examples
Test Case1:
I/P : { 1,42,59,43,68,44 };
O/P: return 5 (Selected ZIG ZAG array 1 < 42 > 43< 68 > 44)
Test case2:
I/P: { 100,42,54,2,5 };
O/P: return 5 (slected ZIg Zag array 100> 42 <54>2 < 5)
Test case 3:
I/P: { 1,42,54,20,1 };
O/P: return 3 {slected Zig zag array 1<42>20}| Report Duplicate | Flag | PURGE
Software Developer - 0of 0 votes
AnswerGiven a string of numbers separated by spaces figure out whether or not you can arrive at 42 with the numbers using only addition, subtraction, and multiplication using java or javascript
- jsduder November 21, 2015 in United States| Report Duplicate | Flag | PURGE
Service Now Software Developer Algorithm - 0of 0 votes
AnswersDesign auto complete for booking.com
- Qasim November 12, 2015 in Netherlands| Report Duplicate | Flag | PURGE
Booking.com Software Developer System Design - 2of 2 votes
AnswersWrite a function to test if the given set of brackets are balanced or not. e.g. {{}}{)([][]
- Qasim November 12, 2015 in Netherlands| Report Duplicate | Flag | PURGE
Booking.com Software Developer Algorithm - 1of 3 votes
AnswersGiven a random string S and another string T with unique elements, find the minimum consecutive sub-string of S such that it contains all the elements in T.
- Saghar H November 05, 2015 in United States
example:
S='adobecodebanc'
T='abc'
answer='banc'| Report Duplicate | Flag | PURGE
Facebook Software Developer Algorithm - 0of 0 votes
AnswersCount the Mines Problem:
- jsduder October 19, 2015 in United States
Your program will first read an integer N from stdin.
Then it will then read N lines of N integers separated by spaces.
Each integer in this Grid will be either 1 or 0.
The program then outputs an N x N Grid where each Grid element represents the number of 1's surrounding that element, (excluding the element itself).
For (column, row) = (0, 0), surrounding element indices are (0,1) (1,0) and (1,1).
Similarly for (1,1), surrounding element indices are (0,0) (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) and (2,2).
Constraints:
Your output lines should not have any trailing or leading white space
Maximum Dimension of Grid = 1000 x 1000
Example Input:
"3 0 1 0 0 0 0 1 0 0"
Expected output:
1 0 1
2 2 1
0 1 0| Report Duplicate | Flag | PURGE
xyz Software Developer Algorithm - 0of 0 votes
Answersadd 2 huge numbers represented by linked list. Each linked list element represents a 4 digit number:
- capricornkmu October 17, 2015 in United States for OpenStack
linked list1 : 8798 -> 8765 -> 1243 -> 9856 -> 8888 -> 0914
linked list 2: 8710 -> 5634 -> 1276 -> 8123 -> 1354 -> 9876
output: ................-> ............. ..-> 7980->0243 -> 0790| Report Duplicate | Flag | PURGE
Ebay Software Developer C
Open Chat in New Window