Getting difficult to solve such easy questoin

Please help why this solution is not working. It 'll take just second to go through my approach. Help would be appreciated.
https://www.codechef.com/viewsolution/35631489

Can you explain your check function?

When you want others to look at code and help, try to keep it as less ugly as possible. Write variable names that makes sense, or add a comment about what you’re trying to do.

Anyways, I think ur on the right path, basically ur checking occurences of x points and y points and if it’s odd, that’s the answer in that axis.

Well let me tell you an easier way than using a stupid arraylist<>. Use a MAP. HashMap/TreeMap.

As you sorted your array, you can also use stack here,

when stack is empty -> push element

when stack is not empty
if top of the stack is == element -> then pop
else push element

If you repeat this process for entire array list, then at the end there will be only one element in the stack, and that will be the missing element (because it is occurring odd no. of times).
This approach is similar to the balance parenthesis check using stack.

2 Likes

Wow, never thought we can solve it using stack. Nice.

Similar approach is applied for questions like Balanced Parenthesis.

Yes

@sachinpant1326
I think your approach is correct, the error is happening when large input is provided

Input 1
2
2
4 1
4 1
5 1
5 1
6 2
6 2
6 3
2
1 1
1 2
4 6
2 1
9 6
9 3
4 3

Expected output:
6 3
2 2

The output of your code:
6 3
2 2

Input 2
2
2
40000000 10000000
40000000 10000000
50000000 10000000
50000000 10000000
60000000 20000000
60000000 20000000
60000000 30000000
2
10000000 10000000
10000000 20000000
40000000 60000000
20000000 10000000
90000000 60000000
90000000 30000000
40000000 30000000

Expected output:
60000000 30000000
20000000 20000000

The output of your code:
40000000 10000000
10000000 10000000

2 Likes

I have not asked you to use what. I simply wanted why my approach is not working. And why do i use map or hashmap, if I have approach of my own using arraylist.

I don’t think comments were necessary as it was just some line of code which is easy to understand by just looking over it. And please first look at the code then reply.

Buddy thank for your help. But did you thought why it was happening? Just look at the comparison of arraylist.get(i) and arraylist.get(i-1). You’ll get to know.
And thanks for your test case, because of which I solved it.

Don’t call arraylist stupid, it’s on you how foolishly you use them. I solved it check this link for correct answer.
https://www.codechef.com/viewsolution/35639333
It was not because of arraylist. It was because of arraylist.get(i)== arraylist.get(i-1).
I was comparing object not the value of that object.

Well approach. But now look at these check function. How is it.
https://www.codechef.com/viewsolution/35639333

I have not asked you to use what. I simply wanted why my approach is not working

yes you didn’t but telling you better way is better isn’t it? Also I think I already mentioned, write readable code if you want others to help, the garbage you wrote in name of code was hard to even look at.

And why do i use map or hashmap, if I have approach of my own using arraylist.

Hahahaha It’s like saying, “I can go from A to B using a horse, I don’t need to learn to drive a car”.

I don’t think comments were necessary as it was just some line of code which is easy to understand by just looking over it

If you think comments are unnecessary, then I give up.

And please first look at the code then reply.

I did read your code, I mentioned it:

Anyways, I think ur on the right path, basically ur checking occurences of x points and y points and if it’s odd, that’s the answer in that axis.
Well let me tell you an easier way than using a stupid arraylist<>. Use a MAP. HashMap/TreeMap.

Maybe first learn to read properly and then do something else.

I was tryna make ur life easier, Ofc ik arraylists are good but using a pickaxe to break wood is stupid.
When there’s an easier way, maybe you should put aside ur ego and learn new things.

You are having ego problem because of which you didn’t understand my response and wrote a great comment with such a perfection. I think, If you would have focused this much on viewing the code, it wouldn’t be a garbage for you.
In the comment @code_symbol understand it and gave a testcase to me, but you don’t . I think you should start learning language first. Words like ‘garbage’ doesn’t suit to someone who can’t even understand 20 lines of code.
First thing, If you were getting difficult to understand it. You should have passed it. It is for someone, who can really help.
if I really wanted an easier way, I would have looked on editorial. I passed it here for some reason so that I can really understand what the real problem is. Not for such suggestion like " Use hashmap or treemap".
And please first clear you basic, then tell what to do or not. And please don’t waste you time on this anymore.

@sachinpant1326 well I agree with @sucks_at_cp on the fact that comments are necessary. Because if you look, I saw your code and after sometime I understood what your Check function did. Maybe I am not too good in coding, but a small comment could help to understand the code

yeah it could,in a hurry I forget. But writing shits and giving alternatives doesn’t suits him.

First, no I’m not having ego problems pfft.

If you would have focused this much on viewing the code, it wouldn’t be a garbage for you.

I did look at it, I showed that in my first comment too, but that doesn’t change the fact that it was trash.

If you think your code wasn’t garbage, then you really need to understand what is “good code”. Now in a competition you don’t need to write good code, you just need to write “fast enough” code that works, because TIME. But if you’re sharing it with someone, asking for help, then you should atleast add a few comments, have better variable names etc.

Words like ‘garbage’ doesn’t suit to someone who can’t even understand 20 lines of code.

Trash talking in ur place is a bad idea, fyi I did this question while you DIDN’T, so sit down.

Not for such suggestion like " Use hashmap or treemap".

You have some sort of superiority complex? Just because I told you that you can use something better, you get hurt ?? and u say I’ve ego problems.
Do you even wanna improve?
Lemme tell you, even using map was inefficient, we could just xor all Xs and Ys to get the answer.

And please first clear you basic, then tell what to do or not. And please don’t waste you time on this anymore.

Again, stop trying to trash talk, my basics are way clearer than yours.
Also about your love for ArrayList<>, have fun using them in a multi threaded application. You’ll have a good time.

yeah it could,in a hurry I forget

You forgot to add comments, but when I pointed it out, you got mad and started trash talking me?

But writing shits and giving alternatives doesn’t suits him.

That’s just nonsense, you don’t even know me, how can you write doesn’t suit him,
you even assumed gender here. LOL. (i’m male but what if it was a female who wrote, you’ll get so much more to apologize because these days people get mad at everything)

Thanks for your help.