0% found this document useful (0 votes)
10 views

Problem Sheet

The document contains a comprehensive list of various coding problems and solutions from platforms like LeetCode and InterviewBit, categorized by different data structures and algorithms such as Dynamic Programming, Hashmaps, Priority Queues, and more. Each entry includes links to specific problems, often with descriptions and potential strategies for solving them. The document serves as a resource for programmers looking to enhance their problem-solving skills across a wide range of topics.

Uploaded by

Rohith Nalluri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Problem Sheet

The document contains a comprehensive list of various coding problems and solutions from platforms like LeetCode and InterviewBit, categorized by different data structures and algorithms such as Dynamic Programming, Hashmaps, Priority Queues, and more. Each entry includes links to specific problems, often with descriptions and potential strategies for solving them. The document serves as a resource for programmers looking to enhance their problem-solving skills across a wide range of topics.

Uploaded by

Rohith Nalluri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

DP

https://leetcode.com/problems/number-of-music-playlists/solutions/3870327/c-dynamic-programming-cod
e-breakdown/. IMP
https://leetcode.com/problems/stone-game-v/description/
https://leetcode.com/problems/make-array-strictly-increasing/description/
https://leetcode.com/problems/odd-even-jump/. IMP
https://leetcode.com/problems/remove-boxes/description/. IMP
https://leetcode.com/problems/minimum-xor-sum-of-two-arrays/description/
https://leetcode.com/problems/find-the-maximum-length-of-a-good-subsequence-ii/solutions/5280172/jav
a-c-python-dp-o-nk/
https://leetcode.com/problems/find-the-minimum-area-to-cover-all-ones-ii/description/
https://leetcode.com/problems/minimum-cost-to-connect-two-groups-of-points/description/
https://leetcode.com/problems/strange-printer/
https://leetcode.com/problems/pizza-with-3n-slices/description/
https://www.naukri.com/code360/problems/mining-diamonds_4244494?source=youtube&campaign=strive
r_dp_videos&utm_source=youtube&utm_medium=affiliate&utm_campaign=striver_dp_videos
https://leetcode.com/problems/house-robber-ii/description/
https://leetcode.com/problems/super-ugly-number/description/
https://leetcode.com/problems/minimum-cost-tree-from-leaf-values/description/
https://www.interviewbit.com/problems/tushars-birthday-bombs/
https://leetcode.com/problems/cherry-pickup/description/
https://leetcode.com/problems/palindrome-partitioning-iii/description/
https://www.geeksforgeeks.org/problems/distinct-palindromic-substrings5141/1?itm_source=geeksforgee
ks&itm_medium=article&itm_campaign=bottom_sticky_on_article
https://leetcode.com/problems/maximum-number-of-non-overlapping-palindrome-substrings/description/
https://leetcode.com/problems/number-of-longest-increasing-subsequence/description/
https://leetcode.com/problems/cat-and-mouse-ii/description/
https://www.geeksforgeeks.org/problems/minimum-number-of-jumps-1587115620/1
https://leetcode.com/problems/minimum-operations-to-make-array-equal-to-target/description/
https://leetcode.com/problems/maximum-number-of-points-with-cost/submissions/1358876069/?envType
=daily-question&envId=2024-08-17
https://leetcode.com/problems/count-ways-to-build-rooms-in-an-ant-colony/description/
https://leetcode.com/problems/ugly-number-ii/description/?envType=daily-question&envId=2024-08-18
https://leetcode.com/problems/count-different-palindromic-subsequences/description/
https://leetcode.com/problems/minimum-swaps-to-make-sequences-increasing/
https://leetcode.com/problems/minimum-number-of-visited-cells-in-a-grid/
https://leetcode.com/problems/minimum-skips-to-arrive-at-meeting-on-time/description/
https://leetcode.com/problems/count-palindromic-subsequences/description/
https://leetcode.com/problems/number-of-music-playlists/description/
https://leetcode.com/problems/minimum-cost-to-merge-stones/description/
https://leetcode.com/problems/minimum-total-distance-traveled/description/?envType=daily-question&env
Id=2024-10-31
https://www.interviewbit.com/problems/merge-elements/
https://leetcode.com/problems/filling-bookcase-shelves/description/
https://www.interviewbit.com/problems/sub-matrices-with-sum-zero/
https://www.interviewbit.com/problems/tiling-with-dominoes/
https://www.interviewbit.com/problems/queen-attack/
https://www.interviewbit.com/problems/min-jumps-array/
https://www.interviewbit.com/problems/longest-arithmetic-progression/
https://leetcode.com/problems/minimum-cost-to-merge-stones/description/


Hashmaps
https://leetcode.com/problems/count-k-subsequences-of-a-string-with-maximum-beauty/description/
https://leetcode.com/problems/max-points-on-a-line/description/
https://leetcode.com/problems/palindrome-rearrangement-queries/description/


Priority QUEUE
https://leetcode.com/problems/put-marbles-in-bags/description/
https://leetcode.com/problems/minimum-cost-to-hire-k-workers/description/
https://leetcode.com/problems/pizza-with-3n-slices/
https://leetcode.com/problems/sliding-window-maximum/description/?envType=problem-list-v2&envId=mg
ain9mt&
https://leetcode.com/problems/maximum-number-of-eaten-apples/description/
https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended/description/
https://www.geeksforgeeks.org/problems/minimize-max-distance-to-gas-station/1
https://leetcode.com/problems/find-the-k-sum-of-an-array/description/
https://leetcode.com/problems/find-building-where-alice-and-bob-can-meet/
https://leetcode.com/problems/time-to-cross-a-bridge/description/


BIT Manipulations
https://www.geeksforgeeks.org/problems/count-total-set-bits-1587115620/1
https://leetcode.com/problems/single-number-ii/
https://leetcode.com/problems/maximum-students-taking-exam/description/
https://leetcode.com/problems/smallest-sufficient-team/description/
https://leetcode.com/problems/maximum-students-taking-exam/description/
https://leetcode.com/problems/maximize-grid-happiness/description/
https://leetcode.com/problems/select-cells-in-grid-with-maximum-score/description/
https://leetcode.com/problems/maximum-xor-score-subarray-queries/description/
https://leetcode.com/problems/chalkboard-xor-game/description/
https://leetcode.com/problems/parallel-courses-ii/description/
https://leetcode.com/problems/shortest-path-to-get-all-keys/
https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array/description/
https://codeforces.com/contest/1879/problem/D
https://leetcode.com/problems/number-of-subarrays-with-and-value-of-k/description/
https://leetcode.com/problems/make-the-xor-of-all-segments-equal-to-zero/description/
https://leetcode.com/problems/apply-operations-on-array-to-maximize-sum-of-squares/
https://leetcode.com/problems/minimum-one-bit-operations-to-make-integers-zero/description/




Miscellaneous
https://leetcode.com/problems/strange-printer/description/
https://www.interviewbit.com/problems/points-on-the-straight-line/
https://leetcode.com/problems/minimum-number-of-k-consecutive-bit-flips/?envType=daily-question&envI
d=2024-06-24
https://leetcode.com/p5roblems/the-skyline-problem/description/
https://www.geeksforgeeks.org/optimal-partition-of-an-array-into-four-parts/ try in o(n) using prefix and
suffix method and kadane
https://www.interviewbit.com/problems/count-total-set-bits/
https://leetcode.com/problems/the-skyline-problem/
https://www.geeksforgeeks.org/problems/redundant-parenthesis--170647/1
https://www.geeksforgeeks.org/problems/magnet-array-problem3743/1
https://www.geeksforgeeks.org/problems/longest-repeating-and-non-overlapping-substring3421/1?itm_so
urce=geeksforgeeks&itm_medium=article&itm_campaign=bottom_sticky_on_article
https://www.interviewbit.com/problems/longest-subarray-length/
https://leetcode.com/problems/queue-reconstruction-by-height/description/
https://leetcode.com/problems/find-the-duplicate-number/description/
https://leetcode.com/problems/minimum-interval-to-include-each-query/description/?envType=problem-list
-v2&envId=mgain9mt
https://leetcode.com/problems/maximum-sum-circular-subarray/description/
https://leetcode.com/problems/count-good-triplets-in-an-array/description/. do this again
https://leetcode.com/problems/count-of-range-sum/description/
https://leetcode.com/problems/reverse-pairs/description/
https://codeforces.com/contest/1996/problem/D
https://leetcode.com/problems/count-the-number-of-substrings-with-dominant-ones/
https://leetcode.ca/2021-10-15-2031-Count-Subarrays-With-More-Ones-Than-Zeros/
https://leetcode.com/problems/powx-n/description/
https://leetcode.com/problems/beautiful-arrangement-ii/
https://leetcode.com/problems/find-array-given-subset-sums/description/
https://leetcode.com/problems/maximize-the-minimum-powered-city/
https://leetcode.com/problems/sorted-gcd-pair-queries/description/
https://leetcode.com/problems/russian-doll-envelopes/description/
https://leetcode.com/problems/longest-valid-parentheses/description/
https://leetcode.com/problems/valid-permutations-for-di-sequence/description/
https://leetcode.com/problems/divide-an-array-into-subarrays-with-minimum-cost-ii/submissions/1424121
919/
https://leetcode.com/problems/make-array-empty/
https://thejoboverflow.com/problem/44/
https://leetcode.com/problems/maximum-number-of-groups-with-increasing-length/description/
https://leetcode.com/problems/special-binary-string/description/





Graphs
https://leetcode.com/problems/minimum-height-trees/
https://leetcode.com/problems/shortest-path-with-alternating-colors/
https://leetcode.com/problems/minimum-cost-of-a-path-with-special-roads/solutions/3468350/c-priority-qu
eue-dp-dijkstra/
https://leetcode.com/problems/shortest-path-visiting-all-nodes/description/
https://leetcode.com/problems/most-profitable-path-in-a-tree/solutions/2807150/2-dfs-1-dfs-simple-approa
ch-c/
https://leetcode.com/problems/sum-of-distances-in-tree/description/
https://leetcode.com/problems/minimum-edge-reversals-so-every-node-is-reachable/description/
https://leetcode.com/problems/maximum-path-quality-of-a-graph/
https://leetcode.com/problems/critical-connections-in-a-network/description/
https://www.geeksforgeeks.org/problems/travelling-salesman-problem2732/1
https://leetcode.com/problems/minimum-cost-to-reach-destination-in-time/
https://leetcode.com/problems/second-minimum-time-to-reach-destination/description/
https://leetcode.com/problems/longest-cycle-in-a-graph/description/
https://leetcode.com/problems/shortest-cycle-in-a-graph/submissions/1280321790/
https://www.geeksforgeeks.org/problems/vertex-cover/1
https://leetcode.com/problems/bus-routes/description/
https://leetcode.com/problems/race-car/description/
https://leetcode.com/problems/remove-boxes/description/
https://leetcode.com/problems/cat-and-mouse/description/
https://leetcode.com/problems/modify-graph-edge-weights/submissions/1302628550/
https://leetcode.com/problems/count-visited-nodes-in-a-directed-graph/description/
https://leetcode.com/problems/minimum-weighted-subgraph-with-the-required-paths/description/
https://leetcode.com/problems/minimum-cost-to-convert-string-ii/description/
https://leetcode.com/problems/count-the-number-of-houses-at-a-certain-distance-ii/
https://leetcode.com/problems/remove-max-number-of-edges-to-keep-graph-fully-traversable/description/
?envType=daily-question&envId=2024-06-30
https://leetcode.com/problems/cat-and-mouse-ii/description/
https://leetcode.com/problems/second-minimum-time-to-reach-destination/description/?envType=daily-qu
estion&envId=2024-07-28
https://leetcode.com/problems/check-if-the-rectangle-corner-is-reachable/description/
https://www.thejoboverflow.com/problem/397/
https://www.thejoboverflow.com/problem/56/
https://www.thejoboverflow.com/problem/151/
https://leetcode.com/problems/rank-transform-of-a-matrix/description/
https://leetcode.com/problems/bricks-falling-when-hit/description/
https://leetcode.com/problems/detect-cycles-in-2d-grid/description/
https://codeforces.com/problemset/problem/1985/H1
https://leetcode.com/problems/reachable-nodes-in-subdivided-graph/description/?envType=problem-list-v
2&envId=shortest-path
https://leetcode.com/problems/maximum-points-after-collecting-coins-from-all-nodes/submissions/137989
2792/
https://leetcode.com/problems/reconstruct-itinerary/submissions/1387546417/
https://leetcode.com/problems/cracking-the-safe/description/
https://leetcode.com/problems/largest-component-size-by-common-factor/description/
https://leetcode.com/problems/trapping-rain-water-ii/description/. solve using bfs
https://leetcode.com/problems/count-the-number-of-houses-at-a-certain-distance-ii/description/
https://leetcode.com/problems/number-of-good-paths/description/


Arrays
https://leetcode.com/problems/closest-room/description/
https://leetcode.com/problems/minimum-number-of-k-consecutive-bit-flips/?envType=daily-question&envI
d=2024-06-24
https://leetcode.com/problems/search-a-2d-matrix-ii/description/
https://www.geeksforgeeks.org/problems/find-missing-and-repeating2512/1?utm_source=youtube&utm_
medium=collab_striver_ytdescription&utm_campaign=find-missing-and-repeating
https://leetcode.com/problems/majority-element-ii/
https://leetcode.com/problems/majority-element/
https://leetcode.com/problems/132-pattern/
https://leetcode.com/problems/sort-characters-by-frequency/ o(n)
https://leetcode.com/problems/maximum-sum-of-3-non-overlapping-subarrays/description/
https://leetcode.com/problems/minimum-swaps-to-group-all-1s-together-ii/description/?envType=daily-que
stion&envId=2024-08-02
https://leetcode.com/problems/sliding-window-maximum/
https://leetcode.com/problems/time-needed-to-rearrange-a-binary-string/description/
https://leetcode.com/problems/count-subarrays-with-fixed-bounds/description/
https://leetcode.com/problems/container-with-most-water/description/​
https://leetcode.com/problems/first-missing-positive/
https://leetcode.com/problems/shortest-distance-after-road-addition-queries-ii/description/
https://leetcode.com/problems/beautiful-arrangement-ii/
https://leetcode.com/problems/count-substrings-that-satisfy-k-constraint-ii/description/
https://www.geeksforgeeks.org/cses-solutions-missing-coin-sum/
https://www.thejoboverflow.com/problem/88/
https://www.thejoboverflow.com/problem/348/
https://leetcode.com/problems/perfect-rectangle/description/
https://leetcode.com/problems/rectangle-area-ii/description/
https://leetcode.com/problems/contain-virus/description/
https://leetcode.com/problems/find-array-given-subset-sums/description/
https://leetcode.com/problems/lexicographical-numbers/?envType=daily-question&envId=2024-09-21
https://leetcode.com/problems/reverse-subarray-to-maximize-array-value/description/
https://leetcode.com/problems/minimum-initial-energy-to-finish-tasks/description/
https://leetcode.com/problems/maximum-building-height/description/
https://leetcode.com/problems/paths-in-matrix-whose-sum-is-divisible-by-k/description/


Binary search
https://leetcode.com/problems/maximum-total-beauty-of-the-gardens/
https://leetcode.com/problems/median-of-two-sorted-arrays/description/?envType=problem-list-v2&envId=
mgain9mt&
https://leetcode.com/problems/longest-common-subpath/description/
https://www.geeksforgeeks.org/problems/minimize-max-distance-to-gas-station/1
https://leetcode.com/problems/count-substrings-that-satisfy-k-constraint-ii/description/
https://www.interviewbit.com/problems/red-zone/
https://leetcode.com/problems/maximum-running-time-of-n-computers/description/



Strings
https://leetcode.com/problems/sort-characters-by-frequency/. O(n) solve
https://leetcode.com/problems/longest-happy-prefix/description/
https://leetcode.com/problems/special-binary-string/description/
https://leetcode.com/problems/last-substring-in-lexicographical-order/description/
https://leetcode.com/problems/smallest-k-length-subsequence-with-occurrences-of-a-letter/description/

Trees
https://leetcode.com/problems/binary-tree-cameras/description/
https://leetcode.com/problems/count-ways-to-build-rooms-in-an-ant-colony/description/
https://leetcode.com/problems/path-sum-iii/
https://codeforces.com/problemset/problem/161/D
https://leetcode.com/problems/difference-between-maximum-and-minimum-price-sum/
https://leetcode.com/problems/height-of-binary-tree-after-subtree-removal-queries/description/
https://leetcode.com/problems/kth-ancestor-of-a-tree-node/description/
https://leetcode.com/problems/maximum-points-after-collecting-coins-from-all-nodes/submissions/137989
2792/
https://leetcode.com/problems/delete-node-in-a-bst/submissions/1396774586/


STACKS
https://leetcode.com/problems/number-of-visible-people-in-a-queue/
https://leetcode.com/problems/minimum-time-to-complete-all-tasks/description/
https://leetcode.com/problems/next-greater-element-iv/
https://leetcode.com/problems/sum-of-total-strength-of-wizards/description/
https://www.geeksforgeeks.org/problems/the-celebrity-problem/1














segment trees template
BUILD,QUERY
#include <bits/stdc++.h>
using namespace std;
void build(vector<int> &a,vector<int> &seg,int node,int start,int end){
if (start==end) seg[node]=a[start];
else {
int mid=(start+end)>>1;
build(a,seg,2*node,start,mid);
build(a,seg,2*node+1,mid+1,end);
seg[node]=min(seg[2*node],seg[2*node+1]);
}
}
int query(vector<int> &seg,int node,int start,int end,int left,int right){
if (left>end || right<start) return INT_MAX;
else if (start>=left && right>=end) return seg[node];
else {
int mid=(start+end)>>1;
int l=query(seg,2*node,start,mid,left,right);
int r=query(seg,2*node+1,mid+1,end,left,right);
return min(l,r);
}
}
int main(){
int n,q;cin>>n>>q;
vector<int> a(n);
for (int i=0;i<n;i++) cin>>a[i];
vector<int> seg(4*n);
build(a,seg,1,0,n-1);
for (int i=0;i<q;i++){
int a,b;cin>>a>>b;
a--;b--;
cout<<query(seg,1,0,n-1,a,b)<<endl;
}
BUILD, UPDATE,QUERY
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void build(vector<ll> &a,vector<ll> &seg,ll node,ll start,ll end){
if (start==end) seg[node]=a[start];
else {
ll mid=(start+end)>>1;
build(a,seg,2*node,start,mid);
build(a,seg,2*node+1,mid+1,end);
seg[node]=min(seg[2*node],seg[2*node+1]);
}
}
void update(vector<ll> &seg,ll node,ll start,ll end,ll ind,ll val){
if (ind>end || ind<start) return;
if (start==ind && end==ind) seg[node]=val;
else {
ll mid=(start+end)>>1;
update(seg,2*node,start,mid,ind,val);
update(seg,2*node+1,mid+1,end,ind,val);
seg[node]=min(seg[2*node],seg[2*node+1]);
}
}
ll query(vector<ll> &seg,ll node,ll start,ll end,ll left,ll right){
if (left>end || right<start) return INT_MAX;
else if (start>=left && right>=end) return seg[node];
else {
ll mid=(start+end)>>1;
ll l=query(seg,2*node,start,mid,left,right);
ll r=query(seg,2*node+1,mid+1,end,left,right);
return min(l,r);
}
}
int main(){
ll n,q;cin>>n>>q;
vector<ll> a(n);
for (ll i=0;i<n;i++) cin>>a[i];
ll treesize=4*n;
vector<ll> seg(4*n);
build(a,seg,1,0,n-1);
for (ll i=0;i<q;i++){
ll c,a,b;cin>>c>>a>>b;
if (c==1){
a--;
update(seg,1,0,n-1,a,b);
}
else {
a--;b--;
cout<<query(seg,1,0,n-1,a,b)<<endl;
}
}
}

You might also like