Skip to content

completed design - 2#2473

Open
yashhh-23 wants to merge 1 commit into
super30admin:masterfrom
yashhh-23:master
Open

completed design - 2#2473
yashhh-23 wants to merge 1 commit into
super30admin:masterfrom
yashhh-23:master

Conversation

@yashhh-23
Copy link
Copy Markdown

No description provided.

Copilot AI review requested due to automatic review settings June 4, 2026 18:32
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds Java solutions for two LeetCode “design” problems (Queue using Stacks, and Design HashMap), including complexity notes and brief approach explanations.

Changes:

  • Implemented MyQueue using two stacks with amortized O(1) operations.
  • Implemented MyHashMap using separate chaining via bucketed linked lists.
  • Expanded header comments with complexity, status, and approach notes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Sample.java
Comment on lines +46 to +59
}

//Problem 2:Design Hashmap (https://leetcode.com/problems/design-hashmap/)

// Time Complexity : O(1) for put, get, and remove operations.
// Space Complexity : O(n) in the worst case if all keys hash to the same bucket, but on average it will be O(1) if the hash function distributes keys equally.
// Did this code successfully run on Leetcode : Yes
// Any problem you faced while coding this : I understood the problem and implemented the solution but faced issues on how to write the code in java according to problem requirements.

// Your code here along with comments explaining your approach
//used an array of buckets, and each bucket stores a linked list of (key, value) pairs. The hash function key % SIZE decides which bucket a key belongs to, and if multiple keys land in the same bucket, we keep them in that list. For put, get, and remove, we only scan one bucket.
import java.util.LinkedList;

class MyHashMap {
Comment thread Sample.java
Comment on lines +10 to +14
import java.util.Stack;

class MyQueue {
private Stack<Integer> inStack;
private Stack<Integer> outStack;
Comment thread Sample.java
Comment on lines +61 to +68
private LinkedList<int[]>[] buckets;

public MyHashMap() {
buckets = new LinkedList[SIZE];
for (int i = 0; i < SIZE; i++) {
buckets[i] = new LinkedList<>();
}
}
Comment thread Sample.java
Comment on lines +50 to +51
// Time Complexity : O(1) for put, get, and remove operations.
// Space Complexity : O(n) in the worst case if all keys hash to the same bucket, but on average it will be O(1) if the hash function distributes keys equally.
@super30admin
Copy link
Copy Markdown
Owner

Create Queue using Stacks (Sample.java)

Strengths:

  1. Correct implementation of the two-stack queue approach
  2. Good use of a helper method (move()) to avoid code duplication between pop() and peek()
  3. Clear comments explaining the approach
  4. Proper encapsulation with private fields
  5. Amortized O(1) time complexity achieved

Areas for Improvement:

  1. The solution only addresses Problem 1, but the submission includes Problem 2 (Design Hashmap) which is outside the scope of this evaluation
  2. Could add null/edge case handling for robustness, though the problem constraints make this less critical
  3. Consider adding @Override annotations for overridden methods if implementing an interface

Overall, this is a solid implementation that correctly solves the problem with good code structure and efficiency.

VERDICT: PASS


Implement Hash Map

Strengths:

  • Clean implementation with good separation of concerns
  • Well-documented with comments explaining the approach
  • Correctly handles key updates in put() method
  • Proper handling of non-existent keys returning -1
  • Good choice of bucket size (1009, a prime number) for better hash distribution

Areas for Improvement:

  • The solution includes Problem 1 (Queue using Stacks) which wasn't part of the assignment - focus on just the HashMap problem
  • Could consider using a custom Node class instead of int[] for better type safety and readability
  • The hash function could be slightly improved with a better prime multiplier for better distribution

Overall, the HashMap implementation is solid and meets all requirements.

VERDICT: PASS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants