## ThoughtWorks Interview Question for Applications Developers

• 0

Country: United States
Interview Type: In-Person

Comment hidden because of low score. Click to expand.
0
of 0 vote

Isn't the output wrong 3+14 = 17 but as of question no two integers should prode integer in set but 17 is in set

Comment hidden because of low score. Click to expand.
0
of 0 vote

Isn't the output wrong 3+14 = 17 but as of question no two integers should prode integer in set but 17 is in set

Comment hidden because of low score. Click to expand.
0
of 0 vote

Do you know the answer or have any hint to solve this question?

Comment hidden because of low score. Click to expand.
0
of 0 vote

Do you know the solution or have any hint for this question?

Comment hidden because of low score. Click to expand.
0
of 0 vote

wouldn't it be easier if you just pick the last m integers from n-1,n-2...etc

like in case of n=20 m=5

[19, 18, 17, 16, 15]

Comment hidden because of low score. Click to expand.
0

This solution will not work in all cases..

Comment hidden because of low score. Click to expand.
0

Will not always work..

Comment hidden because of low score. Click to expand.
0

I understand I read the question as Shouldn't produce number in set..

Comment hidden because of low score. Click to expand.
0
of 0 vote

What about 3+11 = 14, 6+11 = 17 ??.. The question is vague and constraints are not well defined. In many cases a solution may not exist.

Comment hidden because of low score. Click to expand.
0
of 0 vote

This is the best solution I could come up with

1. from 2 to n-1 add one number to set

2. for each new added number find sum with existing from set

note: step two is important if you want to maximise a+b=c triplets

``````public static void main(String[] args) {
ArrayList<Integer> set = new ArrayList<>();
Scanner in = new Scanner(System.in);

System.out.print("Enter limit n : ");
int n = in.nextInt();
System.out.print("Enter limit m : ");
int m = in.nextInt();

outer:
for (int i = 2; i < n && set.size() < m; i++) {
int size = set.size();
if (set.contains(i)) continue;
inner:
for (int j = size; j < set.size(); j++) {
for (int k = 0; k < j; k++) {
int sum = set.get(j) + set.get(k);
if (sum >= n) continue inner;
if (set.contains(sum)) continue;
if (set.size() < m)
else break outer;
}
}
}

System.out.println("the set is " + set.toString());
}``````

the check num>=n checks if the num has exceeded the n limit

to ensure a num is added only once we check for set contains num

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.