WAP at last
Stay hungry, stay foolish!!!!
Saturday, 7 September 2024
Good thoughtful question on Binary search on answers
Thursday, 8 August 2024
Detect cycle via BFS
Tuesday, 16 July 2024
Two pointer approach in sliding window using hashmap
Monday, 3 June 2024
Priority queue medium variant leetcode question
Problem statement link: https://leetcode.com/problems/largest-values-from-labels/
Solution:
import java.util.*;
class Pair{
int value;int type;
public Pair(int value,int type)
{
this.value=value;this.type=type;
}
}
class Solution {
public int largestValsFromLabels(int[] values, int[] labels, int numWanted, int useLimit) {
PriorityQueue<Pair> pq=new PriorityQueue<Pair>((a,b)->(b.value-a.value));
for(int i=0;i<values.length;i++)
{
pq.add(new Pair(values[i],labels[i]));
}
Map<Integer,Integer> mp=new HashMap<>();
int result=0;int i=0;
while(i<numWanted && !pq.isEmpty())
{
Pair p= pq.poll();
if(mp.get(p.type)==null)
{
mp.put(p.type,1);
result+=p.value;
i+=1;
}
else if(mp.get(p.type)!=null && mp.get(p.type)<useLimit)
{
result+=p.value;
mp.put(p.type,mp.get(p.type)+1);
i+=1;
}
}
return result;
}
}
Saturday, 20 April 2024
Detect a cycle in an undirected graph using dfs
Friday, 19 April 2024
Simplified dfs traversal in a graph
Shortest path in undirected graph with unit weight starting from start node via bfs
BFS Q1) Level of nodes
Problem link: https://www.geeksforgeeks.org/problems/level-of-nodes-1587115620/1
Simplified cycle detection via bfs
Simplified bfs traversal in a graph
Simplified Make adjacency list and add edge in graph
Cycle detection in Graph via BFS
Good thoughtful question on Binary search on answers
Problem link: https://leetcode.com/problems/maximize-score-of-numbers-in-ranges/description/ Solution: //import java.util.Arrays; class So...
-
// Grid Unique Paths-->2-D dp concept(space optimised) // tc = O(mxn) // sc = O(n) --> array import java.util.*; class dp { pub...
-
// Grid Unique Paths-->2-D dp concept(Tabulation) // tc = O(mxn) // sc = O(mxn) --> extra dp array import java.util.*; class dp { ...
-
// Count Grid Unique Paths-->2-D dp concept(Memoization) // tc = O(mxn) -->at max there will be n*m calls of recursion // sc = O((n-1...