Computer Science problems in Java.
- Grind 75 โ A curated LeetCode problem list that encompasses common interview topics: https://lnkd.in/gM_en6dQ ( grind75.com for more)
- NeetCode โ For crystal clear explanations of LeetCode solutions: https://lnkd.in/gcKGJP3f
- Hello Interview โ AI-guided system design mock interviews (website + YouTube): https://lnkd.in/gw4k4rau
- interviewing.io System Design Guide โ Especially the first three sections, packed with fun analogies: https://lnkd.in/g9MKnE85
- Exponent โ A platform for peer-to-peer mock interviews: https://lnkd.in/gunUpv3y
- LinkedList
- Fast and Slow Pointer
- Midpoint of LinkedList
- Nth element removal from the end of the list
- Fast and Slow Pointer
- Dynamic Programming: There are two strings S1 and S2. Find the length of the largest substring which contains all and only the characters of S2.
- You have N cars numbered from 1 to N. Car 1 is open and all the other cars are closed. Each car has a list of keys where key i can open the car i. Find out if we can open all the cars.
- Two Pointers
- Sliding Window
- Prefix Sums
- Merge Intervals
- Binary Search (and Variants)
- Sorting-Based Patterns
- Fast and Slow Pointers
- Backtracking & Recursive Search
- Divide and Conquer
- Linked List Techniques (Dummy Node, In-place Reversal)
- Stacks and Queues
- Monotonic Stack / Queue
- Expression Evaluation (Two Stacks)
- String Manipulation & Regular Expressions
- Hashmaps & Frequency Counting
- Binary Trees & BSTs (Traversal, Construction, Properties)
- Path Sum & Root-to-Leaf Techniques
- Kth Largest/Smallest Elements (Heaps / QuickSelect)
- Top K Frequent Elements
- Merge K Sorted Lists
- Dynamic Programming (Including Knapsack, Range DP, etc.)
- Greedy & Interval Partitioning
- Graph Traversals (BFS, DFS)
- Graph Algorithms (DAGs, MSTs, Shortest Paths, etc.)
- Design Problems (LRU Cache, Twitter, etc.)
๐๐ฟ๐ฟ๐ฎ๐๐ ๐ฎ๐ป๐ฑ ๐ฆ๐๐ฟ๐ถ๐ป๐ด๐:
- Find the maximum sum subarray.
- Find all substrings that are palindromes.
- Implement the "two-sum" problem.
- Implement Kadane's algorithm for maximum subarray sum.
- Find the missing number in an array of integers.
- Merge two sorted arrays into one sorted array.
- Check if a string is a palindrome.
- Find the first non-repeating character in a string.
- Write a program to remove duplicates from a sorted array.
๐๐ถ๐ป๐ธ๐ฒ๐ฑ ๐๐ถ๐๐๐:
- Reverse a linked list. โ
- Detect a cycle in a linked list.
- Find the middle of a linked list. โ
- Merge two sorted linked lists. โ
- Implement a stack using linked list.
- Find the intersection point of two linked lists.
๐ฆ๐๐ฎ๐ฐ๐ธ๐ ๐ฎ๐ป๐ฑ ๐ค๐๐ฒ๐๐ฒ๐:
- Implement a stack using an array.
- Implement a stack that supports push, pop, top, and retrieving the minimum element.
- Implement a circular queue.
- Design a max stack that supports push, pop, top, retrieve maximum element.
- Design a queue using stacks.
๐ง๐ฟ๐ฒ๐ฒ๐ ๐ฎ๐ป๐ฑ ๐๐ถ๐ป๐ฎ๐ฟ๐ ๐ฆ๐ฒ๐ฎ๐ฟ๐ฐ๐ต ๐ง๐ฟ๐ฒ๐ฒ๐:
- Find the height of a binary tree.
- Find the lowest common ancestor of two nodes in a binary tree.
- Validate if a binary tree is a valid binary search tree.
- Serialize and deserialize a binary tree.
- Implement an inorder traversal of a binary tree.
- Find the diameter of a binary tree.
- Convert a binary tree to its mirror tree.
๐๐ฟ๐ฎ๐ฝ๐ต๐:
- Implement depth-first search (DFS).
- Implement breadth-first search (BFS).
- Find the shortest path between two nodes in an unweighted graph.
- Detect a cycle in an undirected graph using DFS.
- Check if a graph is bipartite.
- Find the number of connected components in an undirected graph.
- Find bridges in a graph.
๐ฆ๐ผ๐ฟ๐๐ถ๐ป๐ด ๐ฎ๐ป๐ฑ ๐ฆ๐ฒ๐ฎ๐ฟ๐ฐ๐ต๐ถ๐ป๐ด:
- Implement (bubble, insertion, selection, merge) sort.
- Implement quicksort.
- Implement binary search.
- Implement interpolation search.
- Find the kth smallest element in an array.
- Given an array of integers, count the number of inversions it has. An inversion occurs when two elements in the array are out of order.
๐๐๐ป๐ฎ๐บ๐ถ๐ฐ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ด (๐๐ฃ):
- How do you find the nth Fibonacci number using dynamic programming?
- Write a dynamic programming solution for the 0/1 knapsack problem.
- Memoization to optimize recursive solutions in dynamic programming?
- Implement a dynamic programming algorithm to find the longest common subsequence of two strings.
- The coin change problem.
- Tabulation approach in dynamic programming.
๐๐ฎ๐ฐ๐ธ๐๐ฟ๐ฎ๐ฐ๐ธ๐ถ๐ป๐ด:
- Backtracking algorithm to solve the N-Queens problem.
- Generate all permutations of a given set using backtracking?
- Implement backtracking to solve the Sudoku puzzle.
- Subset sum problem.
- Graph coloring problem using backtracking.
- Write a backtracking algorithm to find the Hamiltonian cycle in a graph.
๐๐ฎ๐๐ต๐ถ๐ป๐ด:
- Implement a hash table using separate chaining.
- First non-repeating character in a string using hashing.
- Collision resolution techniques in hashing.
- Write a function to solve the two-sum problem using hashing.
- How can you implement a hash set data structure?
- Count the frequency of elements in an array using hashing.
๐๐ฒ๐ฎ๐ฝ:
- Implement a priority queue using a min-heap.
- How do you merge K sorted arrays using a min-heap?
- Write a function to perform heap sort algorithm.
- Find the kth largest element in an array using a min-heap.
- Implement a priority queue using a min-heap.
- How do you build a max heap from an array?
๐ง๐ฟ๐ถ๐ฒ๐:
- Implement a trie data structure.
- Write a function to search for a word in a trie.
- How can you implement autocomplete feature using a trie?
- Deleting a word from a trie.
- Write a function to find all words matching a pattern in a trie.
๐๐ฟ๐ฒ๐ฒ๐ฑ๐ ๐๐น๐ด๐ผ๐ฟ๐ถ๐๐ต๐บ๐:
- Solve the activity selection problem using a greedy algorithm.
- Implement Huffman coding using a greedy algorithm.
- Write a function to find the minimum spanning tree using Prim's algorithm.
- Coin change problem.
- Dijkstra's algorithm using a greedy approach.
- Implement the job sequencing problem using a greedy algorithm.
- Sliding Window and Two Pointer
- Greedy (Mostly Sorting)
- Binary Search on Answer
- All Combinations/Permutations/Ways
- K Smallest / K Largest โ Heaps
- Prefix/Suffix/Word Search โ Tries
- Graph - DFS / BFS
- Topological Sort
- Bitwise XOR
- Tree - DFS/BFS
- Slow and Fast Pointers - LinkedList
- Parenthesis Problems - Stack
- DP - Knapsack Problem
- Arrays, Strings, Linked Lists
- Stacks, Queues, Deques
- HashMaps, HashSets
- Trees (Binary Trees, BST, Trie)
- Graphs (BFS, DFS, shortest path, cycle detection)
- Heaps / Priority Queues
- Sliding Window, Two Pointers, Backtracking
- Dynamic Programming (Tabulation, Memoization)
- Sorting & Searching (Binary Search variants)
-
Fast and Slow Pointer
- Cycle detection method
- O(1) space efficiency
- Linked list problems
-
Merge Intervals
- Sort and merge
- O(n log n) complexity
- Overlapping interval handling
-
Sliding Window
- Fixed/variable window
- O(n) time optimization
- Subarray/substring problems
-
Islands (Matrix Traversal)
- DFS/BFS traversal
- Connected component detection
- 2D grid problems
-
Two Pointers
- Dual pointer strategy
- Linear time complexity
- Array/list problems
-
Cyclic Sort
- Sorting in cycles
- O(n) time complexity
- Constant space usage
-
In-place Reversal of Linked List
- Reverse without extra space
- O(n) time efficiency
- Pointer manipulation technique
-
Breadth First Search
- Level-by-level traversal
- Uses queue structure
- Shortest path problems
-
Depth First Search
- Recursive/backtracking approach
- Uses stack (or recursion)
- Tree/graph traversal
-
Two Heaps
- Max and min heaps
- Median tracking efficiently
- O(log n) insertions
-
Subsets
- Generate all subsets
- Recursive or iterative
- Backtracking or bitmasking
-
Modified Binary Search
- Search in variations
- O(log n) time
- Rotated/specialized arrays
-
Bitwise XOR
- Toggle bits operation
- O(1) space complexity
- Efficient for pairing
-
Top 'K' elements
- Use heap/quickselect
- O(n log k) time
- Efficient selection problem
-
K-way Merge
- Merge sorted lists
- Min-heap based approach
- O(n log k) complexity
-
0/1 Knapsack (Dynamic Programming)
- Choose or skip items
- O(n * W) complexity
- Maximize value selection
-
Unbounded Knapsack (Dynamic Programming)
- Unlimited item choices
- O(n * W) complexity
- Multiple item selection
-
Topological Sort (Graphs)
- Directed acyclic graph
- Order dependency resolution
- Uses DFS or BFS
-
Monotonic Stack
- Maintain increasing/decreasing stack
- Optimized for a range queries
- O(n) time complexity
-
Backtracking
- Recursive decision-making
- Explore all possibilities
- Pruning with constraints
-
Union Find
- Track and merge connected components
- Used for disjoint sets
- Great for network connectivity
-
Greedy Algorithm
- Make locally optimal choices
- Efficient for problems with optimal substructure
- Covers tasks like activity selection, minimum coins
โ Build a strong foundation (WEEKS 1-4)
๐ฏ Focus on the most frequently used topics:
- Arrays: Prefix sum, sliding window problems.
- Strings: Two-pointer technique, pattern matching.
- Linked Lists: Reversal, cycle detection.
- Stacks/Queues: Monotonic stacks, bracket problems.
๐ฏ Resources:
- Neetcode 150 for a structured problem set.
- Take U Forward (YouTube): Great explanation for each video.
- GFG: Topic-wise problems with solutions.
โ Practice Problems Strategically (WEEKS 5-12)
๐ฏ Tackle problems in three stages:
- Stage 1: Solve 50 easy problems to get comfortable.
- Stage 2: Solve 75 medium problems, focusing on optimization.
- Stage 3: Solve 15 hard problems if targeting FAANG.
๐ฏ Platforms to Practice:
- LeetCode: Sort by difficulty or tags (arrays, DP). and contests
- HackerRank: For warm-ups and hiring contests.
โ Master Core Algorithms and Data Structures (WEEKS 13โ16)
๐ฏKey Focus Areas:
- Binary Search: Search in rotated arrays, peak elements.
- Recursion and Backtracking: Subsets, permutations, Sudoku solver.
- Dynamic Programming:
- Classic problems like Fibonacci, Knapsack, LIS.
- Understand bottom-up and top-down approaches.
- Trees and Graphs:
- BFS/DFS traversal, shortest path (Dijkstra).
๐ฏ Resources:
- Neetcode Playlists: Trees, DP, and Graphs.
- Tushar Roy YouTube Channel: Algorithm deep dives.
- LeetCode Discussion Forums: Optimized solutions and hints.
โ Learn System Design Basics (WEEKS 17-20)
๐ฏ What to Focus On:
- Scalability: Load balancing, horizontal scaling.
- Caching: Strategies like LRU cache.
- Databases: SQL VS. NOSQL, partitioning, sharding.
- Design Patterns: Singleton, Observer, Factory.
๐ฏ Resources:
- System Design Primer (GitHub): Beginner to advanced.
- Grokking the System Design Interview: Simplified concepts.
- Designing Data-Intensive Applications: Real-world system insights.
โ Mock Interviews and Communication (WEEKS 21-24)
๐ฏ What to Do:
- Pair up with peers or mentors for mock interviews.
๐ฏ Use platforms:
- Pramp: Peer-to-peer interviews.
- InterviewBit: Mock interviews with industry experts.
- Record yourself solving problems and analyze
โ Behavioral Questions (ONGOING)
๐ฏ What to Expect:
- Questions around teamwork, challenges, and problem-solving.
- Example:
- Tell me about a time you resolved a conflict in a team.
- How do you prioritize tasks under tight deadlines?
๐ฏ How to Prepare:
- Use the STAR method: Situation, Task, Action, Result.
- Focus on stories that highlight leadership, impact, and learning.
- Mock practice with peers or record yourself.
๐ฏ Resources:
- Big Interview (Behavioral Prep): Comprehensive practice.
- Google common behavioral interview questions.
๐ญ. ๐๐ฎ๐๐ฎ ๐ฆ๐๐ฟ๐๐ฐ๐๐๐ฟ๐ฒ๐ ๐ฎ๐ป๐ฑ ๐๐น๐ด๐ผ๐ฟ๐ถ๐๐ต๐บ๐ (๐๐ฆ๐)
- Arrays, Strings, Linked Lists
- Stacks, Queues, Deques
- HashMaps, HashSets
- Trees (Binary Trees, BST, Trie)
- Graphs (BFS, DFS, shortest path, cycle detection)
- Heaps / Priority Queues
- Sliding Window, Two Pointers, Backtracking
- Dynamic Programming (Tabulation, Memoization)
- Sorting & Searching (Binary Search variants)
๐ฎ. ๐๐ผ๐ฟ๐ฒ ๐๐ฎ๐๐ฎ (๐๐ฎ๐๐ฎ ๐ด+)
- OOP principles
- Collections framework (List, Map, Set, Queue)
- Concurrency and Multithreading
- Java Streams and Lambda expressions
- Functional Interfaces
- Exception handling
- Memory Management, Garbage Collection
- Design Patterns (Singleton, Factory, Strategy, etc.)
๐ฏ. ๐ฆ๐ฝ๐ฟ๐ถ๐ป๐ด & ๐๐ฎ๐ฐ๐ธ๐ฒ๐ป๐ฑ ๐๐ฒ๐๐ฒ๐น๐ผ๐ฝ๐บ๐ฒ๐ป๐
- Spring Core
- Spring Boot (auto-configuration, starters, profiles)
- Spring MVC (REST APIs, controllers, exception handling)
- Validation, Logging, Caching
- Unit Testing (JUnit5, Mockito)
- Spring AOP
- Swagger/OpenAPI
- REST vs SOAP, Idempotency, API versioning
๐ฐ. ๐๐ผ๐-๐๐ฒ๐๐ฒ๐น ๐๐ฒ๐๐ถ๐ด๐ป (๐๐๐)
- Object-oriented design principles (SOLID, DRY, YAGNI)
- Design Patterns
- Class Diagrams, Sequence Diagrams
- Design real-world systems: Parking Lot, Elevator, Splitwise, BookMyShow, etc.
๐ฑ. ๐๐ถ๐ด๐ต-๐๐ฒ๐๐ฒ๐น ๐๐ฒ๐๐ถ๐ด๐ป (๐๐๐)
- Basics of distributed systems
- Load Balancing, Caching, Database Sharding
- Microservices architecture (communication, service discovery, circuit breakers)
- Messaging Queues (Kafka, RabbitMQ)
- Scalability, Availability, CAP Theorem
- Design problems: URL shortener, Rate limiter, WhatsApp, etc.
๐ฒ. ๐ฆ๐ผ๐ณ๐ ๐ฆ๐ธ๐ถ๐น๐น๐ & ๐๐ป๐๐ฒ๐ฟ๐๐ถ๐ฒ๐ ๐ฃ๐ฟ๐ฒ๐ฝ๐ฎ๐ฟ๐ฎ๐๐ถ๐ผ๐ป
- STAR format for behavioral questions
- Systematic problem-solving approach
- Good communication for explaining thought process
- JDK Standard Library โ https://docs.oracle.com/en/java/javase/24/docs/api/index.html
- Apache Commons Lang โ https://commons.apache.org/components.html
- Lang3 Utilities โ https://commons.apache.org/proper/commons-lang/javadocs/api-release/index.html
- Collections
- Text โ https://commons.apache.org/proper/commons-text/userguide.html
- IO โ https://commons.apache.org/proper/commons-io/
- CSV โ https://commons.apache.org/proper/commons-csv/apidocs/index.html
- Configuration โ https://commons.apache.org/proper/commons-configuration/userguide/user_guide.html
- Math โ https://commons.apache.org/proper/commons-math/userguide/index.html
- Numbers โ https://commons.apache.org/proper/commons-numbers/userguide/index.html
- Statistics โ https://commons.apache.org/proper/commons-math/userguide/stat.html
- Geometry โ https://commons.apache.org/proper/commons-geometry/userguide/index.html
- Java Datafaker โ https://s01.oss.sonatype.org/service/local/repositories/releases/archive/net/datafaker/datafaker/2.4.2/datafaker-2.4.2-javadoc.jar/!/index.html
- Guava: Google Core Libraries โ https://guava.dev/releases/snapshot-jre/api/docs/
- Agrona: High-Performance data structures and utility methods for Java โ https://github.com/aeron-io/agrona
- Eclipse Collections is a collections framework for Java with optimized data structures and a rich, functional, and fluent API. โ https://github.com/eclipse-collections/eclipse-collections
- Batch framework for Java โ https://github.com/j-easy/easy-batch
- Object-functional extension for Java โ https://github.com/vavr-io/vavr
- Java binary serialization and cloning โ https://github.com/EsotericSoftware/kryo
- LLD of chess
- Design a chess game
- Design a simple URL shortening service.
- Design a basic chat application.
- Design a file storage system.
- Design a simple social media platform.
- Design a simple search engine.
- Design a simple e-commerce website.
- Design a basic ride-sharing system.
- Design a basic video streaming service.
- Design a simple recommendation system.
- Design a basic food delivery app.
- Design a parking lot management system.
- Design a simple music streaming service.
- Design a basic online ticket booking system.
- Design a simple note-taking application.
- Design a weather forecasting system.
- Design a basic email service.
- Design a file synchronization system.
- Design a simple calendar application.
- Design a basic online quiz platform.
- Design a user authentication system.
- Design a URL-shortening service like bit.ly.
- Design a distributed key-value store like Redis.
- Design a scalable social network like Facebook.
- Design a scalable recommendation system like Netflix.
- Design a distributed file system like Hadoop's HDFS.
- Design a real-time messaging system like WhatsApp.
- Design a web crawler like Google.
- Design a distributed cache like Memcached.
- Design a content delivery network (CDN) like Cloudflare.
- Design a scalable search engine like Google.
- Design a ride-sharing system like Uber.
- Design a video streaming service like YouTube.
- Design an online food delivery system like Zomato.
- Design a collaborative document editing system like Google Docs.
- Design an e-commerce platform like Amazon.
- Design a recommendation system for an online marketplace.
- Design a fault-tolerant distributed database system.
- Design a scalable event-driven system like Twitter.
- Design a scalable photo-sharing platform like Instagram.
- Design a distributed task scheduling system.
These patterns provide various object creation mechanisms, which increase the flexibility and reuse of existing code.
- Factory Method
- Abstract Factory
- Builder
- Prototype
- Singleton
These patterns explain how to assemble objects and classes into larger structures while keeping these structures flexible and efficient.
- Adapter
- Bridge
- Composite
- Decorator
- Facade
- Flyweight
- Proxy
These patterns are concerned with algorithms and the assignment of responsibilities between objects.
- Chain of Responsibility
- Command
- Iterator
- Mediator
- Memento
- Observer
Model: GPT-4o, o3-mini-high
Please explain LeetCode question [ID], including its solution and complexity. Also, specify which topics and patterns it belongs to and suggest similar questions.
Please show a Step-by-Step Walkthrough with this example input:
{Your example input}
You should show the value of each variable in each step and summarized it as a table.
Make Minimal Changes to Fix Your Broken Solution (If you can brainstorm a whiteboard and write a solution)
Do not attempt solutions for hard problems right away โ too much time will be spent. Brainstorm solvable problems.
Template to ask if failed:
Here is my solution to LeetCode question {ID}, but it doesn't pass all test cases.
Please modify the minimal number of lines to make it work and explain why.
{Your solution}
Below are the test cases it failed:
{Failed test cases}.
Execute the code on a test case data and explain each execution step by step.
Please show a Step-by-Step Walkthrough with this example input:
{Your example input}
You should show the value of each variable in each step and summarized it as a table.
The next topic is {topic_name}. please tell me about the
1. core ideas and the keys(or steps) to solve this kinds of Leetcode problem
2. please summarize and create a table including
1. Category: the type of Leetcode problem
2. Description: explain the pattern
3. Priority: high, medium, or low based on whether itโs important for interview preparation
4. Why: explain the reason for the priority
5. Representative questions: 2 or 3 representative questions
Letโs talk about the pattern of {PATTERN} from the topic of the {TOPIC}, Based on the questions you recommended, compare and explain 2 or 3 questions to help me
1. Understand this pattern well
2. Easier to identify these pattern
3. Understand the templates to solve these problems
Please give me the following output
1. The basic idea of this pattern and how to identify this pattern
2. a summary table comparing representative leetcode question
3. code templates and their counterpart leetcode questions (at least two questions)
4. then go to the details of each question. While explaining each question, please
1. give all details about the question description
2. in terms of solution, focus on the goal to learn the pattern, ignore details that are too specific
template = """Please explain the LeetCode question: {question_title}.
Your output should include the following headers:
- **Problem Description**
- Input & Output
- Examples
- **Topics and Patterns**
- **Solution & Complexity**
- Key Ideas
- **Java Solution**
- Code
- Explanation
- Step-by-Step Walkthrough (summarized as a table)
- Detailed Complexity Analysis
- **Similar Questions** (including question title, difficulty, description, and why it is similarโorganized in a table)
(Please avoid opening and closing remarks; the more detailed, the better.)"""
TRICK TO LEARN DSA FASTER!!! As promised, here is a post on DSA prep. As mentioned before, follow neetcode.io for intuition building and category by category prep. He became famous organically due to how good he is with whiteboarding. This is not sponsored( I am not a creator ) Now I can ask you to grind day and night, but like every exam, DSA has tricks to build intuition faster like CAT or JEE: Base rules of DSA and human psychology:
- Never jump from category to category and solve random problems - your brain will never form a pattern in chaos.
- Never ever attempt the first problem on your own from any given category - just knowing how linked list works is not enough data for your mind to solve a tricky linked list problem, just like how knowing permutation formula is not enough to solve a HOTs permutation problem from NCERT. You will jeopardize your confidence and have no interest further to learn. Best practice/trick: Step 1: Let us go to any given category, say Graphs. DO NOT attempt the first problem on your own. Watch neetcode solve first 5 or 6 questions till your mind has a grasp of what graph based problems and solutions look like. Observation before jumping into it is key. Step 2: Now that your mind has gotten a feel of the pattern, come to 7th question for example and just attempt the approach. DO NOT CODE. verify if your intuition aligns with neetcode. Do that for next few problems till you feel somewhat confident that you are able to do it. Step 3: Rewrite all the 10 problems you have watched videos of so far, yourself, since you know the solutions already. Step 4: once you are done with previous 3 steps, go to problem number 11 and attempt this completely on your own, from intuition to code and verify. You will make some mistakes but that is ok, you are close, keep going! Keep doing this for every category till you feel confident in each of them. Step 5: Great! you feel like you can do this! revise all the problems you have done in all categories. Step 6: Start solving one completely new problem per day to see if you are able to put it in a category and then find the right solution. Do this till you feel somewhat confident to give interviews. This method is a lot faster than the traditional "Work hard till you figure it out" method. Also, not to mention, the number of problems a person needs to build pattern varies from person to person, so the numbers I have mentioned are averge numbers. Try this for atleast one category and let me know how it works out in DMs! Works best on following categories: Graphs, Trees, Heaps, Tries, Intervals, Stacks, Sliding window, Linked list. Rest of them need more number of problems and practice.