mohit
 0of 0 votes
AnswersGiven an array arr and a number n, you have to find whether there exist a subset in arr whose sum is n. You have to print length of the subset.
 mohit in India
1. There exists only one subset like that
2. All number in arr are positive Report Duplicate  Flag
Amazon SDE1 Dynamic Programming  0of 0 votes
AnswersSuppose you are a stock trader and you can do as many trades but if you stop you can't do another trade. You can start with any trade. Given an array of profits/loss of trades and find the maximum profit you can make.
Input:
Number of trades
Profit/loss in each trade
Output:
Max Profit
Ex:
Input:7 1 2 3 4 2 3 1
Output:
10
Explaination: Trade of [1,2,3,4]
Input:5 2 3 4 1 2
Output:
3
P.S: Any solution than BruteForce.
 mohit in India Report Duplicate  Flag
Nagarro Intern  0of 0 votes
AnswersGiven two integer arrays A and B.
B contains exactly same numbers as A except two additional numbers. Find the two elements with minimum time and space complexity.
for ex: A ={1, 4, 2, 6, 3}
B = {4, 0,7, 6, 3, 2, 1}
ans: 0 7
I came with this solution:
 mohit in United StatesArrays.sort(A); Arrays.sort(B); int i=0, j=0; while(j<=i+2  i<A.length){ if(A[i]==B[j]){ ++i; ++j} else{ System.out.println(b[j]); j++; } } if(j==A.length+1){ System.out.println(B[j++]+" "B[j]); } if(j==B.length) System.out.println)(B[j]);
 Report Duplicate  Flag
Alcatel Lucent  0of 0 votes
AnswersHow will you dictionary sort integers without converting them to strings.
 mohit in United States
For ex: 1 2 10 20 100 110
Ans: 1 10 100 110 2 20. Report Duplicate  Flag
Alcatel Lucent  0of 0 votes
AnswersGiven an input n, find the smallest number x such that x % n = 0 and sum of the digits in x is equal to n.
 mohit in India
Note: x is so large even long long int can't keep it.
It is obvious that find the sum of digits using (x/10) gives timeout, so how can its complexity be reduced. Report Duplicate  Flag

1 Answer
Algorithms
Given an input n, find the smallest number x such that x % n = 0 and sum of the digits in x is equal to n.
 mohit September 22, 2014
Note: x is so large even long long int can't keep it.
It is obvious that find the sum of digits using (x/10) gives timeout, so how can its complexity be reduced. Flag
Open Chat in New Window
Radix sort is for strings
 mohit December 25, 2014