## mohit

BAN USER- 1of 1 vote

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 | PURGE

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 Brute-Force.

- mohit in India| Report Duplicate | Flag | PURGE

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 States`Arrays.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 | PURGE

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 | PURGE

- 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 | PURGE

Rep**nickjonson885**, Consultant at ASUI am Department director in a Libera company. I live in Buffalo NY, USA. I am a hard worker girl ...

Rep**kristinedavila9**, Android Engineer at ABC TECH SUPPORTI am Kristine Davila Professor and director at Clinical Psychology. Having experience of 6 years in my career. I have ...

Rep**haroldjmaloney**, Accountant at ASUHi, I am a Computer systems administrator from texas. Experienced in running a wide variety of software development Company. Looking ...

Rep**joankelly306**, Site Manager at EFIHi, I am Joan from Fairbanks, in USA. I have been a Food Product Manager in a Food Barn Company ...

Rep**AmberBrook**, Animator at A9Hi everyone, Done my master of arts in specialized journalism.Also an member of society of professional journalists since 2015 ...

Rep**kennypmillerk**, AT&T Customer service email at 247quickbookshelpMy name is Kenny and I am working as a trusted investor in Pittsburgh USA.I identify / set up a ...

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window

Radix sort is for strings

- mohit December 25, 2014