Recent Interview Questions
0of 0 votesGive three Hash tables has some values.you need compare three hash tables and store the common values in fourth hash table?
0of 0 votesEliminate all ‘b’ and ‘ac’ in an array of characters, you have to replace them in-place, and you are only allowed to iterate over the char array once.
Examples:
abc -> ac
ac->''
react->rt
0of 0 votesThe bin packing problem is an example of a wide set of problems. The task is to find how many set sized bins are required to hold a number of differently sized boxes. How many bins (10 units high) are required to contain the following boxes (1,3,4 and 5 units high)?
0of 0 votesWrite a program to calculate the Loan Balance, where a person borrows an amount A and in return he/she agrees to make N payments per year, each of amount P. While the person is repaying the loan, interest will accumulate at an annual percentage rate of R, and this interest will be compounded N times a year (along with each payment). Therefore, the person must continue paying these installments of amount P until the original amount and any accumulated interest is repaid.
NOTE: The formula to calculate the amount that the person needs to repay after T years is -
Balance Amount after T years = A[(1+R/N)^NT]-P
0of 0 votesCode to check if a given short string is a substring of a main string. Can you get a linear solution (O(n)) if possible?
0of 0 votesGiven a circular linked list, find the mid element of the linked list.
0of 0 votesExplain how you would implement a multi-map in Java without using any collections?
0of 0 votesTwo numbers are represented as linked lists. Both lists are of same length. Add them without manipulating the lists and without a second traversal.
-1of 1 voteWhat is system.gc() and runtime.gc() ?
1of 1 voteWhich will take less time to retrieve the data if numbers are present in hashmap and sorted array .
0of 0 votesAn array of zero and non zero integer are their having range 10000 (i.e length of array is 10,000)
Arrange the array in such a way that zero comes first and after that the non zero integer.
1of 1 voteFind duplicates in infinite range .
Which data structure to be used to give efficient solution.?
I answered HashMap .
How to implement using boolean array.?
0of 0 votesYou are given an application which sometimes may go into infinite loop.
Come up with a deployment plan s.t. the erring process is killed as soon as it goes into infinite loop.
0of 0 votesPlease consider the following tables:
Code:
Table Name: Person
Person_Id Name
Table Name: DVD
DVD_ID Owner_ID Title
Here is the query:
Write a query that returns the list of DVDs that belong to owners who own “Superman”
Here is my solution:
Code:
SELECT p.name,d.dvd_id
FROM DVD d,Person p
WHERE p.person_id = d.dvd_id
AND Title = 'Superman' ;
I answered above answer. But interviewer was expecting me to do using Subquery. Is that possible?Please let me know if the above query is correct or not.
0of 0 votesDesign a chess game. Write all classes and methods.
1of 1 voteGiven a large file of (x,y) coordinates. Find the k farthest points from origin.
1of 1 voteGiven a network of printers and systems. Allocate the nearest printer to each system. How will you handle dynamic addition of printers and systems.
3of 3 votesGiven a sorted array which is rotated n number of times. Find out how many times the array is rotated. Time complexity should be less than O(n).
0of 0 votesGiven a Binary Search tree along with the parent pointer, find the next largest node for the given node. Give the time and space complexity. The node Structure is
class Node {
Int data;
Node left;
Node right;
Node parent;
}
0of 0 votesGiven a string in the form of a Linked List, check whether the string is palindrome or not. Don’t use extra memory. Give the time complexity. The node structure is
Class Node {
Char data;
Node next;
}
0of 0 votesAdd a number to array and if there is carry increase array size.
---------------------------
For example input = {7,3,5,3,9} convert this to number 73539, add 1 so it becomes 73540 and convert to array {7,3,5,4,0}.
Array can be of any length, so you can't always represent array in form of in-built number format. So you have to do this summation in-place. Also, how would you increase array size in-case input = {9,9,9} so output = (1,0,0,0}
Assume, all elements of arrays are between 0 and 9.
0of 0 votesAdd a number to array and if there is carry increase array size.
----------------------------------------------------------------------
For example input = {7,3,5,3,9} convert this to number 73539, add 1 so it becomes 73540 and convert to array {7,3,5,4,0}.
Array can be of any length, so you can't always represent array in form of in-built number format. So you have to do this summation in-place. Also, how would you increase array size in-case input = {9,9,9} so output = (1,0,0,0}
Assume, all elements of arrays are between 0 and 9.
0of 0 voteswhat is the difference?
void test(vector<int> vec)
{
//ptint the vec;
}
void test(const vector<int> &vec)
{
//print the vec;
}
0of 0 votesWrite a Javascript program for the following problem -
(Actually, any language is fine with me but it was a JS interview)
Given a large number of strings occurring on a web page, find the largest group of strings that are likely to be swapped with each other.
e.g mat, rat, groom, broom, cat
answer => mat, rat, cat and not groom, broom
I coded edit distance, got hopelessly lost beyond that.
As for hints, he said that it being a web page don't count on traversing a given string more than once.
0of 0 votesHow to write test data for a vendor machine using this coins (50 paise, 1 rupee coin, 2 rupee coin, 5 rupee coin, 10 rupee coin) to get (Tea, Coffee, Ice Tea, Cold Coffee, Milk)
Concept Is
Tea - 50 paise coin
Coffee - 1 rupee coin
Ice Tea - 2 rupee coin
Cold Coffee - 5 rupee coin
Milk - 10 rupee coin
0of 0 votesA log file is of below format
log.txt
=====================================
TIMESTAMP:MM-DD-YYYY
REQUEST:______________________________
RESPONSE:____________________________
SUCCESS:200:________________________
=====================================
TIMESTAMP:MM-DD-YYYY
REQUEST:______________________________
RESPONSE:____________________________
ERROR:400:________________________
=====================================
TIMESTAMP:MM-DD-YYYY
REQUEST:______________________________
RESPONSE:____________________________
ERROR:=500:________________________
=====================================
TIMESTAMP:MM-DD-YYYY
REQUEST:______________________________
RESPONSE:____________________________
ERROR:400:________________________
=====================================
TIMESTAMP:MM-DD-YYYY
REQUEST:______________________________
RESPONSE:____________________________
ERROR:401:________________________
I want the count of error between two given dates.grep '0[6789]:\| 1[01234567]' | ""grep -c "ERROR" log.txt timestamp = grep "TIMESTAMP" awk '$timestamawk>=from&&$timestamp<=to' from="2007/03/20 15:13" to="2007/08/19 14:31" log.txt | grep "ERROR" | wc -l timestamp = grep "TIMESTAMP" echo timestamp | awk -F'[- ]' '$2 >= 25 && $3 <= 04 { print }' | grep -c "ERROR"
0of 0 votesgiven an array of charactes have to replace space with %20. where %20 is considered as 3 characters.write complete code to implement this.
ps: assume that array has enough space at the end that can fit one space character to 3 chacters(%20).import java.io.* char fn(char [] word) { for(int i =1;i<=word.length();i++) { if(char[i]==" " && isArrayRightShiftable(word)){ shiftArrayToRight(word,i); char[i]='%'; char[i+1]='2'; char[i+2]='0'; } } return word; } private boolean isArrayRightShiftable(char[] word) { if(word.length()+2 < 50){ return true; } return false; } private void shiftArrayToRight(char[] word, int i) { for(int j = word.length();j>=i;j--) word[j+2]=word[j]; }
0of 0 votesFind the maxProduct of three numbers from a given integer array.
1. Handle all the cases
2. Interviewer was looking for a complete codepublic int maxPro() { // -5, -4, -3, -2 , 0 Int array[] = new Int[]{4,5,6,0,-5,-7,-2,-10}; Arrays.sort(array); // -10,-7,-5,-2,0,4,5,6 int count =0; for(int i =0; i<array.length();i++){ if(array[i]<0) count = count+1; } int maxProduct =1; if ( array.length()<3){ return -1; } else if( array.length()>=3 ){ int a=1; b=2; if(count>=2){ a = array[0]*array[1]*array[array.length-1]; b = array[array.length-1]*array[array.length-2]*array[array.length-3]; maxProduct = Math.max(a,b); } else if (count == 0 || count == 1 || count == array.length()){ maxProduct = array[array.length-1]*array[array.length-2]*array[array.length-3]; } } return maxProduct; }
0of 0 voteswrite a generic function API in C so it can any data types like:
insert(a); where a can be integer,char,float
struct generic {
void *data;
struct generic *member
}
0of 0 votesReverse a string using C pointers
Ex: "Welcome to India" to "India to Welcome"
