I am getting wrong answer for this problem:

link text

it satisfies all test cases given in problem + few more

my solution:

link text

I am getting wrong answer for this problem:

link text

it satisfies all test cases given in problem + few more

my solution:

link text

Your approach is wrongâ€¦ It wonâ€™t satisfy all the test cases.

First of all you are using an O(n^2) sort that can cause you a TLE. (Sorting is not required though)

You can use the following two methods

1.) Brute Force

2.)Use dynamic programming such that dp[i][j]=1 when there is a sum of j possible up till the ith position.

So you will just have to see the value of dp[n][m].

Check this test case:

1

5 10

2 2 3 4 5

Your solution is giving â€śNOâ€ť while the answer should be â€śYESâ€ť. (2+3+5=10)

1 Like

Maximum value of n is 20. So, sorting would not cause TLE.