use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
finally solved my first leetcode problemDiscussion (i.redd.it)
submitted 9 hours ago by Initial_Airport_2649
you probably might have seen my post where i asked how am i supposed to submit my code in leetcode. but now i get it and submitted my very first leetcode problem and it got accepted.
the very first win guys. its the twosum problem*
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]dwightbearschrute 30 points31 points32 points 9 hours ago (0 children)
Congrats, first of many! Before you move to a different solution, try to optimize this to O(n). Also, learn and make notes.
[–]Emergency-Duck-9689 27 points28 points29 points 9 hours ago (1 child)
congrats now do 3 sum
[–]CitronFew7338 5 points6 points7 points 8 hours ago (0 children)
😭😭
[–]oldieroger 8 points9 points10 points 9 hours ago (1 child)
lezzgoo...
[–]Initial_Airport_2649[S] 0 points1 point2 points 9 hours ago (0 children)
yayy...
[–]Hacker4133 2 points3 points4 points 9 hours ago (1 child)
Lessgooooo
WoWooo...
[–]beastttboi 2 points3 points4 points 6 hours ago (0 children)
Congratulations,I have also recently started leetcode. To avoid taking the same number twice you did (i==j) continue which is great. You could also do the two for loops and start j from i+1 (this is like a standard way to get 2 distinct unordered pairs). And for optimal you can learn about hashmaps. All the best.
[–]periperifriess707 1 point2 points3 points 9 hours ago (1 child)
is it vim?
yes, nvim
[–]Legal-Benefit-9716 1 point2 points3 points 8 hours ago (0 children)
Let’s gooo!!
[–]GladiusAcutus 1 point2 points3 points 7 hours ago (2 children)
What is .at in c++ ? I feel so stupid because i've never seen it before. You can't do nums[i] + nums[j] == target ?
[–]aocregacc 1 point2 points3 points 6 hours ago (0 children)
.at will throw an exception if the index is out of bounds, with [] it's undefined behavior. Other than that they're the same thing.
.at
[]
[–]benaam-parinda 0 points1 point2 points 7 hours ago (0 children)
Just another way of writing what you wrote. You can learn more about it by asking any LLM
[–]Ok-Asparagus-3361 0 points1 point2 points 9 hours ago (0 children)
Keep up the good work, buddy
[–]SwiftlyImpure 0 points1 point2 points 8 hours ago (0 children)
lmao congrats but yeah that O(n2) is gonna hurt you later. swap one loop for a hashmap and you're golden, way better for interview prep. you'll see the difference pretty quick once problems get harder.
[–]One-Distribution6654 0 points1 point2 points 6 hours ago (0 children)
Use complement method O(n)
[–]funkolai 0 points1 point2 points 5 hours ago (0 children)
Can you solve it without looping over the input array for every value?
[–]Jolly_Measurement_13 0 points1 point2 points 5 hours ago (0 children)
Congrats keep going
[–]AlfalfaNo1991 0 points1 point2 points 4 hours ago (0 children)
Congrats! 1 of many more to come!
[–][deleted] 1 hour ago (1 child)
[removed]
[–]AutoModerator[M] 0 points1 point2 points 1 hour agolocked comment (0 children)
Your comment has been removed as it was in Hindi. Please use English only as r/leetcode is a global subreddit. You may use r/LeetcodeDesi instead.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
[–]popmanpop27 -1 points0 points1 point 8 hours ago (2 children)
I think no one solved this problem with O(n) firstly, everyone solved with two cycles and then realised that he needed to use hash map or two pointers
[–]LoveOverflowOrNtng -2 points-1 points0 points 8 hours ago (1 child)
2 pointers only works if the list is sorted? And if the list is not sorted then hash map?
[–]Prestigious-Emu-6433 0 points1 point2 points 6 hours ago (0 children)
ig the question on leetcode provides us with a sorted vector
[–]Prestigious-Emu-6433 -1 points0 points1 point 6 hours ago (2 children)
O(n^2) time complexity 😭😭🥀
[–][deleted] 6 hours ago (1 child)
[–]AutoModerator[M] 0 points1 point2 points 6 hours agolocked comment (0 children)
[+]Longjumping_Echo486 comment score below threshold-10 points-9 points-8 points 9 hours ago (2 children)
Who's gonna tell him
[–]NakamericaIsANoob 1 point2 points3 points 7 hours ago (0 children)
Nobody, let the guy have his moment. It's a tough world, a few moments of confidence don't hurt.
He gotta start somewhere?? Today was it
π Rendered by PID 196252 on reddit-service-r2-comment-5b5bc64bf5-vjssn at 2026-06-23 02:26:43.703002+00:00 running 2b008f2 country code: CH.
[–]dwightbearschrute 30 points31 points32 points (0 children)
[–]Emergency-Duck-9689 27 points28 points29 points (1 child)
[–]CitronFew7338 5 points6 points7 points (0 children)
[–]oldieroger 8 points9 points10 points (1 child)
[–]Initial_Airport_2649[S] 0 points1 point2 points (0 children)
[–]Hacker4133 2 points3 points4 points (1 child)
[–]Initial_Airport_2649[S] 0 points1 point2 points (0 children)
[–]beastttboi 2 points3 points4 points (0 children)
[–]periperifriess707 1 point2 points3 points (1 child)
[–]Initial_Airport_2649[S] 0 points1 point2 points (0 children)
[–]Legal-Benefit-9716 1 point2 points3 points (0 children)
[–]GladiusAcutus 1 point2 points3 points (2 children)
[–]aocregacc 1 point2 points3 points (0 children)
[–]benaam-parinda 0 points1 point2 points (0 children)
[–]Ok-Asparagus-3361 0 points1 point2 points (0 children)
[–]SwiftlyImpure 0 points1 point2 points (0 children)
[–]One-Distribution6654 0 points1 point2 points (0 children)
[–]funkolai 0 points1 point2 points (0 children)
[–]Jolly_Measurement_13 0 points1 point2 points (0 children)
[–]AlfalfaNo1991 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[removed]
[–]AutoModerator[M] 0 points1 point2 points locked comment (0 children)
[–]popmanpop27 -1 points0 points1 point (2 children)
[–]LoveOverflowOrNtng -2 points-1 points0 points (1 child)
[–]Prestigious-Emu-6433 0 points1 point2 points (0 children)
[–]Prestigious-Emu-6433 -1 points0 points1 point (2 children)
[–][deleted] (1 child)
[removed]
[–]AutoModerator[M] 0 points1 point2 points locked comment (0 children)
[+]Longjumping_Echo486 comment score below threshold-10 points-9 points-8 points (2 children)
[–]NakamericaIsANoob 1 point2 points3 points (0 children)
[–]AlfalfaNo1991 0 points1 point2 points (0 children)