Skip to content

Solutions to Leetcode, CareerCup Coding problems

Notifications You must be signed in to change notification settings

pytdev/CodingInterview

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Coding Interview

Language License SayThanks

Why you should follow this repository?

As a student I solved many leetcode problems but unable to identify the most efficient solution and this repo will help you with explanation and data structure wise questions. It's easy to access and time saver before the interview.

Often careercup contains buggy code and most inefficient algorithms. I try to add an effcient one with explanation in my own words.

Feel free to submit pull requests, add issues and be a contributer.

One Stop to top 100 leetcode questions

On the day before interview, don't forget to review these problems. Credit to DevkaPupara

Algorithms

Bit Manipulation

Website Title Solution Time Space Difficulty Note
Careercup Permutation Casewise Java O(2^n) O(1) Medium
Leetcode 50. Pow(x, n) Java O(n) O(1) Medium
Leetcode 89. Gray Code Java O(n) O(1) Medium
Leetcode 137. Single Number II Java O(n) O(1) Medium
Leetcode 190. Reverse Bits Java O(n) O(n) Easy
Leetcode 191. Number of 1 Bits Java O(n) O(1) Easy
Leetcode 260. Single Number III Java O(n) O(1) Medium
Leetcode 401. Binary Watch Java O(n) O(1) Easy
Leetcode 461. Hamming Distance Java O(n) O(1) Easy
Leetcode 338. Counting Bits Java O(nk) O(n) Medium

Arrays

Website Title Solution Time Space Difficulty Note
Leetcode 12. Integer to Roman Java O(n) O(1) Medium
Leetcode 15. 3Sum Java O(n) O(1) Medium
Leetcode 16. 3Sum Closest Java O(n^2) O(1) Medium
Leetcode 26. Remove Duplicates from Sorted Array Java O(n) O(1) Easy
Leetcode 27. Remove Element Java O(n) O(1) Easy
Leetcode 31. Next Permutation Java O(n) O(1) Easy
Leetcode 39. Combination Sum Java O(2^n) O(1) Medium
Leetcode 40. Combination Sum II Java O(2^n) O(1) Medium
Leetcode 46. Permutations Java O(2^n) O(1) Medium
Leetcode 47. Permutations II Java O(2^n) O(1) Medium
Leetcode 66. Plus One Java O(n) O(1) Easy
Leetcode 78. Subsets Java O(2^n) O(n) Medium
Leetcode 90. Subsets II Java O(2^n) O(n) Medium
Leetcode 88. Merge Sorted Array Java O(n) O(1) Easy
Leetcode 120. Triangle Java O(m*n) O(1) Medium
Leetcode 121. Best Time to Buy and Sell Stock Java O(n) O(1) Easy
Leetcode 189. Rotate Array Java O(n) O(1) Easy
Leetcode 217. Contains Duplicate Java O(n) O(1) Easy
Leetcode 228. Summary Ranges Java O(n) O(1) Medium
Leetcode 268. Missing Number Java O(n) O(1) Easy
Leetcode 283. Move Zeroes Java O(n) O(1) Easy
Leetcode 311. Sparse Matrix Multiplication Java O(mnl) O(m*l) Medium
Leetcode 350. Intersection of Two Arrays II Java O(m+n) O(1) Easy
Leetcode 383. Ransom Note Java O(n) O(1) Easy
Leetcode 419. Battleships in a Board Java O(mn) O(1) Medium
Leetcode 442. Find All Duplicates in an Array Java Python O(n) O(1) Easy
Leetcode 561. Array Partition I Java O(nlogn) O(1) Easy
Leetcode 566. Reshape the Matrix Java O(m*n) O(m*n) Easy
Leetcode 598. Range Addition II Java O(n) O(1) Easy
Leetcode 605. Can Place Flowers Java O(n) O(1) Easy
Leetcode 611. Valid Triangle Number Java O(n) O(1) Easy
Leetcode 624. Maximum Distance in Arrays Java O(m*n) O(m*n) Easy
Leetcode 628. Maximum Product of Three Numbers Java O(n) O(1) Easy
Leetcode 643. Maximum Average Subarray I Java O(n) O(1) Easy
Leetcode 674. Longest Continuous Increasing Subsequence Java O(n) O(1) Easy
Leetcode 713. Subarray Product Less Than K Java O(n) O(1) Medium
Leetcode 714. Best Time to Buy and Sell Stock with Transaction Fee Java O(n) O(1) Medium
Leetcode 724. Find Pivot Index Java O(n) O(1) Easy

Strings

Website Title Solution Time Space Difficulty Note
Leetcode 6. ZigZag Conversion Java O(n) O(n) Medium
Leetcode 125. Valid Palindrome Java O(n) O(1) Easy
Leetcode 131. Palindrome Partitioning Java O(2^n) O(1) Medium
Leetcode 139. Word Break Java O(n^2) O(n) Medium
Leetcode 151. Reverse Words in a String Java O(n) O(1) Easy
Leetcode 165. Compare Version Numbers Java O(n) O(1) Medium
Leetcode 168. Excel Sheet Column Title Java O(n) O(1) Easy
Leetcode 205. Isomorphic Strings Java O(n) O(1) Easy
Leetcode 242. Valid Anagram Java O(n) O(n) Easy
Leetcode 243. Shortest Word Distance Java O(n) O(1) Easy
Leetcode 290. Word Pattern Java O(n) O(1) Easy
Leetcode 293. Flip Game Java O(n) O(1) Easy
Leetcode 345. Reverse Vowels of a String Java O(n) O(1) Easy
Leetcode 387. First Unique Character in a String Java O(n) O(n) Easy
Leetcode 389. Find the Difference Java O(n) O(1) Easy
Leetcode 408. Valid Word Abbreviation Java O(n) O(1) Easy
Leetcode 412. Fizz Buzz Java O(n) O(1) Easy
Leetcode 422. Valid Word Square Java O(n) O(1) Easy
Leetcode 479. Largest Palindrome Product Java O(n) O(1) Medium
Leetcode 482. License Key Formatting Java O(n) O(1) Medium
Leetcode 500. Keyboard Row Java O(n) O(1) Easy
Leetcode 520. Detect Capital Java O(n) O(1) Easy
Leetcode 521. Longest Uncommon Subsequence I Java O(n) O(1) Easy
Leetcode 524. Longest Word in Dictionary through Deleting Java O(nk) O(1) Medium
Leetcode 537. Complex Number Multiplication Java O(n) O(1) Medium
Leetcode 541. Reverse String II Java O(n) O(1) Easy
Leetcode 551. Student Attendance Record I Java O(n) O(1) Easy
Leetcode 557. Reverse Words in a String III Java O(n) O(1) Easy
Leetcode 647. Palindromic Substrings Java O(n^2) O(1) Easy
Leetcode 686. Repeated String Match Java O(n) O(1) Easy
Leetcode 771. Jewels and Stones Java O(n) O(1) Easy
Leetcode 848. Shifting Letters Java O(n) O(1) Medium
Leetcode 856. Score of Parentheses Java O(n) O(n) Medium
Leetcode 859. Buddy Strings Java O(n) O(n) Easy

HashMap

Website Title Solution Time Space Difficulty Note
Leetcode 1. Two Sum Java O(n) O(n) Easy
Leetcode 169. Majority Element Java O(n) O(n) Easy
Leetcode 170. Two Sum III - Data structure design Java O(n) O(n) Medium
Leetcode 187. Random DNA Sequence Java O(n) O(n) Medium
Leetcode 219. Contains Duplicate II Java O(n) O(n) Easy
Leetcode 266. Palindrome Permutation Java O(n) O(1) Easy
Leetcode 340. Longest Substring with At Most K Distinct Characters Java O(n) O(n) Hard
Leetcode 347. Top K Frequent Elements Java O(n) O(n) Medium
Leetcode 359. Logger Rate Limiter Java O(n) O(n) Easy
Leetcode 454. 4Sum II Java O(n^2) O(n^2) Medium
Leetcode 506. Relative Ranks Java O(n) O(n) Easy
Leetcode 525. Contiguous Array Java O( ) O( ) Medium
Leetcode 532. K-diff Pairs in an Array Java O(n) O(n) Easy
Leetcode 535. Encode and Decode TinyURL Java O(n) O(1) Medium
Leetcode 594. Longest Harmonious Subsequence Java O(n) O(n) Easy
Leetcode 677. Map Sum Pairs Java O(n) O(1) Easy
Leetcode 760. Find Anagram Mappings Java O(n) O(1) Easy

Trees

Website Title Solution Time Space Difficulty Note
Leetcode 94. Binary Tree Inorder Traversal Java O(n) O(n) Medium
Leetcode 101. Symmetric Tree Java O(n) O(1) Easy
Leetcode 110. Balanced Binary Tree Java O(n) O(1) Easy
Leetcode 111. Minimum Depth of Binary Tree Java O(n) O(1) Easy
Leetcode 144. Binary Tree Preorder Traversal Java O(n) O(n) Medium
Leetcode 173. Binary Search Tree Iterator Java O(1) O(h) Medium
Leetcode 220. Contains Duplicate III Java O(nlogk) O(k) Medium
Leetcode 285. Inorder Successor in BST Java O(h) O(1) Medium
Leetcode 297. Serialize and Deserialize Binary Tree Java O(n) O(n) Medium
Leetcode 298. Binary Tree Longest Consecutive Sequence Java O(n) O(n) Hard
Leetcode 314. Binary Tree Vertical Order Traversal Java O(n) O(n) Medium
Leetcode 404. Sum of Left Leaves Java O(n) O(n) Easy
Leetcode 437. Path Sum III Java O(n) O(1) Easy
Leetcode 513. Find Bottom Left Tree Value Java O(n^2) O(1) Medium
Leetcode 530. Minimum Absolute Difference in BST Java O(v + e) O(1) Easy
Leetcode 543. Diameter of Binary Tree Java O(v + e) O(1) Easy
Leetcode 572. Subtree of Another Tree Java O(m2+n2+mn) O(max(m,n) Easy
Leetcode 606. Construct String from Binary Tree Java O(n) O(1) Easy
Leetcode 617. Merge Two Binary Trees Java O(mn) O(1) Easy
Leetcode 623. Add One Row to Tree Java Medium
Leetcode 637. Average of Levels in Binary Tree Java O(n) O(1) Easy
Leetcode 653. Two Sum IV - Input is a BST Java O(n) O(n) Easy
Leetcode 662. Maximum Width of Binary Tree Java O(n) O(d) Medium
Leetcode 663. Equal Tree Partition Java Medium
Leetcode 677. Map Sum Pairs Java O(n) O(1) Medium HashMap
Leetcode 687. Longest Univalue Path Java O(n) O(1) Easy

Dynamic Programming

Website Title Solution Time Space Difficulty Note
Leetcode 53. Maximum Sum Subarray Java O(n) O(1) Easy
Leetcode 62. Unique Paths Java O(m*n) O(m+n) Easy
Leetcode 70. Climbing Stairs Java O(n) O(1) Easy
Leetcode 91. Decode Ways Java O(n) O(n) Medium
Leetcode 152. Maximum Product Subarray Java O(n) O(1) Medium
Leetcode 198. House Robber Java O(n) O(1) Easy
Leetcode 221. Maximal Square Java O(mn) O(mn) Medium
Leetcode 264. Ugly Number II Java O(n) O(1) Easy
Leetcode 628. Maximum Product of Three Numbers Java O(n) O(1) Easy
Leetcode 646. Maximum Length of Pair Chain Java O(n) O(1) Easy
Leetcode 746. Min Cost Climbing Stairs Java O(n) O(1) Easy

Recursion

Website Title Solution Time Space Difficulty Note
Leetcode 22. Generate Parentheses Java O(4^n) O(n) Medium
Leetcode 50. Pow(x, n) Java O() O(n) Medium
Leetcode 109. Convert Sorted List to Binary Search Tree Java O(n) O(logn) Medium
Leetcode 339. Nested List Weight Sum Java O( ) O( ) Easy
Leetcode 654. Maximum Binary Tree Java O(n log n) O(n) Easy

Heaps

Website Title Solution Time Space Difficulty Note
Leetcode 414. Third Maximum Number Java O(n) O(1) Easy
Leetcode 621. Task Scheduler Java O(n) O(n) Medium

Binary Search

Website Title Solution Time Space Difficulty Note
Leetcode 253. Meeting Rooms II Java O(nlogn) O(n) Medium
Leetcode 278. First Bad Version Java O(logn) O(1) Easy
Leetcode 540. Single Element in a Sorted Array Java O(logn) O(1) Medium

Stack

Website Title Solution Time Space Difficulty Note
Leetcode 20. Valid Parentheses Java O(n) O(n) Easy
Leetcode 155. Min Stack Java O(n) O(1) Easy
Leetcode 232. Implement Queue using Stacks Java O(n) O(n) Easy
Leetcode 388. Longest Absolute File Path Java O(n) O(n) Medium
Leetcode 496. Next Greater Element I Java O(mn) O(m+n) Easy
Leetcode 503. Next Greater Element II Java O(n) O(n) Medium

Queue

Website Title Solution Time Space Difficulty Note
Leetcode 225. Implement Stack using Queues Java O(n) O(1) Easy
Leetcode 346. Moving Average from Data Stream Java O(n) O(1) Easy

LinkedList

Website Title Solution Time Space Difficulty Note
Leetcode 2. Add Two Numbers Java O(n+m) O(n+m) Medium
Leetcode 21. Merge Two Sorted Lists Java O(n) O(1) Easy
Leetcode 24. Swap Nodes in Pairs Java O(n) O(1) Medium
Leetcode 23. Merge k Sorted Lists Java O(n logk) O(1) Hard
Leetcode 83. Remove Duplicates from Sorted List Java O(n) O(1) Easy
Leetcode 148. Sort List Java O(nlogn) O(logn) Medium
Leetcode 203. Remove Linked List Elements Java O(n) O(1) Easy
Leetcode 206. Reverse Linked List Java O(n) O(1) Easy
Leetcode 237. Delete Node in a Linked List Java O(1) O(1) Easy
Leetcode 234. Palindrome Linked List Java O(n) O(1) Medium
Leetcode 328. Odd Even Linked List Java O(n) O(1) Medium
Leetcode 445. Add Two Numbers II Java O(nm) O(m+n) Medium

TwoPointers

Website Title Solution Time Space Difficulty Note
Leetcode 11. Container With Most Water Java O(n) O(1) Medium
Leetcode 209. Minimum Size Subarray Sum Java O(n) O(1) Medium
Leetcode 259. 3Sum Smaller Java O(n) O(1) Medium
Leetcode 360. Sort Transformed Array Java O(n) O(1) Medium
Leetcode 487. Max Consecutive Ones II Java O(n) O(1) Medium
Leetcode 567. Permutation in String Java O(n) O(1) Medium
Leetcode 680. Valid Palindrome II Java O(n) O(1) Easy

BFS

Website Title Solution Time Space Difficulty Note
Leetcode 690. Employee Importance Java O(v+e) O(1) Easy

Sort

Website Title Solution Time Space Difficulty Note
Leetcode 56. Merge Intervals Java O(nlogn) O(1) Medium
Leetcode 57. Insert Interval Java O(n) O(1) Hard
Leetcode 75. Sort Colors Java O(n) O(1) Medium
Leetcode 147. Insertion Sort List Java O(nlogn) O(1) Medium
Leetcode 179. Largest Number Java O(nlogn) O(n) Medium
Leetcode 280. Wiggle Sort Java O(n) O(1) Medium
Leetcode 581. Shortest Unsorted Continuous Subarray Java O(nlogn) O(n) Easy

Math

Website Title Solution Time Space Difficulty Note
Leetcode 204. Count Primes Java O(n) O(n) Easy
Leetcode 223. Rectangle Area Java O(1) O(1) Medium
Leetcode 319. Bulb Switcher Java O(n) O(1) Medium
Leetcode 728. Self Dividing Numbers Java O(n) O(1) Easy

SQL

Website Title Solution Time Space Difficulty Note
Leetcode 177. Nth Highest Salary SQL O(n) O(1) Medium
Leetcode 181. Employees Earning More Than Their Managers SQL O(n) O(1) Easy
Leetcode 197. Rising Temperature SQL O(n) O(1) Easy
Leetcode 597. Friend Requests I: Overall Acceptance Rate SQL O(n) O(1) Easy
Leetcode 627. Swap Salary SQL O(n) O(1) Easy

About

Solutions to Leetcode, CareerCup Coding problems

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 99.1%
  • Other 0.9%