Skip to content

Instantly share code, notes, and snippets.

View d-rat's full-sized avatar
🎯
Focusing

Dilip Singh Dangwal d-rat

🎯
Focusing
  • New Delhi
View GitHub Profile
class Solution {
int[] cache;
public int reversePairs(int[] nums) {
int n = nums.length;
cache = new int[n];
return count(nums, 0, n-1);
}
int count(int[] arr, int l, int r){
if(l==r) return 0;
@d-rat
d-rat / grokking_to_leetcode.md
Created July 4, 2022 06:19 — forked from tykurtz/grokking_to_leetcode.md
Grokking the coding interview equivalent leetcode problems

GROKKING NOTES

I liked the way Grokking the coding interview organized problems into learnable patterns. However, the course is expensive and the majority of the time the problems are copy-pasted from leetcode. As the explanations on leetcode are usually just as good, the course really boils down to being a glorified curated list of leetcode problems.

So below I made a list of leetcode problems that are as close to grokking problems as possible.

Pattern: Sliding Window

class QueueStack {
constructor() {
this.q = [];
}
push(val) {
let size = this.q.length;
this.q.push(val);
while (size--) {
this.q.push(this.q.shift());
}
class Solution {
public List<List<Integer>> levelOrder(TreeNode root) {
List<List<Integer>> ans=new ArrayList<>();
if(root==null) return ans;
List<Integer> level=new ArrayList<>();
Queue<TreeNode> q=new LinkedList<>();
q.offer(root);
q.offer(null);
// Given an unsorted integer array nums, find the smallest missing positive integer.
// You must implement an algorithm that runs in O(n) time and uses constant extra space.
// https://leetcode.com/problems/first-missing-positive/
var firstMissingPositive = function (nums) {
for (let i = 0; i < nums.length; i++) {
if (nums[i] > 0 && nums[i] <= nums.length && nums[i] !== i + 1) {
[nums[i], nums[nums[i] - 1]] = [nums[nums[i] - 1], nums[i]];
i = i - 1;