Can u please say why i'm failing 2 test cases?

please check my code and rectify the errors.

if(c!=1)
	v.push_back(c);

I don’t think you require this if condition. Even if c = 1, you need to insert it into v.

but, if i remove the if condition, then o/p is coming as 0

Please share the new code.

https://ide.codingblocks.com/s/333303 here u go

This is not what I meant, I meant

// if(c!=1)
	v.push_back(c);

i have done that, its still not working

Ohh wait!!
I am soo sorry, my bad!! I didn’t pay much attention to your logic, just looked for errors in code.

The logic is not correct.
What do you think should be the answer for

3
1 2 1

Your code will output 5, but the answer is 7 ({1}, {2}, {3}, {1, 2}, {2, 1}).

Try to see what you are doing wrong, else ask me and I’ll help you.

yes sir, i got it. thank u for ur support!

1 Like