Sunday, November 30, 2025
Contains duplicate - using HashSet (optimized code)
Two Sum - optimized code (using HashMaps)
public int[] twoSum(int[] nums, int target) {
// Phase 2 Logic: HashMap
HashMap<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < nums.length; i++) {
int complement = target - nums[i];
if (map.containsKey(complement)) {
// Success: Return [Old Index, Current Index]
return new int[] { map.get(complement), i };
}
// Store: Key = Number, Value = Index
map.put(nums[i], i);
}
return new int[] {}; // Fallback
}
Tuesday, November 11, 2025
Two Sum in Leetcode
class Solution {
Hash Map in Java!
HashMap: Part of JCF & implements the Map interface.
- Stores element in key-value pairs.
- Keys are unique and values can be duplicated.
Monday, November 10, 2025
Template Literal in JavaScript
1. Calculate total price using template literal.
let pencilPrice = 10;
3917. Count Indices With Opposite Parity (Brute Force) O(n2) + Optimized Solution O(n) + tips LEETCODE WEEKLY 500
class Solution { public int [] countOppositeParity ( int [] nums ) { // approach 1 - checks every pair int n = n...
-
import java.util.*; // Push element at the bottom of stack class StackB { public static String reverseString(String str) { ...
-
#include <iostream> #include <vector> using namespace std; void merge(string arr[], int si, int mid, int ei) { int m = mid;...
-
#include <iostream> using namespace std ; // quote- break down bigger problems into smaller problems // Diamond pattern - /* pseu...