- 187
- 6 004 429
Coder Army
เข้าร่วมเมื่อ 9 ส.ค. 2023
Hi Coder, We are on a mission to create Best Coder in our Country and for that we are putting best content for Students. I am Rohit Negi who graduated from IIT Guwahati and got Highest Placement in India in 2021. I got AIR 202 in GATE CSE in 2020.
Time to Level UP Your Development Journey
We have Launched a Live course on Web Development (MERN Stack) and Blockchain, where we are going to cover each and everything from basic to Advance level. There is no prerequisite of the course.
Buy Course link: rohittnegi.akamai.net.in/new-courses/4-web-development-block-chain
Play store app of Coder Army: play.google.com/store/apps/details?id=com.rohit.negi
Special Diwali Offer: Get it at 4000rs only
Coupon Code: CODER500
Coder Army Website: www.coderarmy.in/
No Prerequisite Required
Course Start Date: 16 sep 2024
Class Timing: 9-10 pm (Mon to Fri) LIVE
Instructor: Rohit Negi
Doubt Support: Discord Group
Recording: It will be available after the class
#webdevelopment #dsa #blockchain #nexus
Course Content
1: Web Development
● Basic of Internet
● HTML
● CSS
● JAVASCRIPT
● React JS
● TypeScript
● NEXT JS
● NODE JS
● Express JS
● MONGODB and Mongoose
● Authentication and Authorization
● WebSockets and WebRTC
● API
● Advance Projects with Deployment
2: BlockChain
● Blockchain Introduction
● Cryptographic Foundations
● Blockchain Internal Working
● Ethereum and it’s Ecosystem
● Solana client side apps
● Smart Contracts
● Solidity from Basic to Advance
● Rust Basic to Advance
● Advance Projects with Deployment
Buy Course link: rohittnegi.akamai.net.in/new-courses/4-web-development-block-chain
Play store app of Coder Army: play.google.com/store/apps/details?id=com.rohit.negi
Special Diwali Offer: Get it at 4000rs only
Coupon Code: CODER500
Coder Army Website: www.coderarmy.in/
No Prerequisite Required
Course Start Date: 16 sep 2024
Class Timing: 9-10 pm (Mon to Fri) LIVE
Instructor: Rohit Negi
Doubt Support: Discord Group
Recording: It will be available after the class
#webdevelopment #dsa #blockchain #nexus
Course Content
1: Web Development
● Basic of Internet
● HTML
● CSS
● JAVASCRIPT
● React JS
● TypeScript
● NEXT JS
● NODE JS
● Express JS
● MONGODB and Mongoose
● Authentication and Authorization
● WebSockets and WebRTC
● API
● Advance Projects with Deployment
2: BlockChain
● Blockchain Introduction
● Cryptographic Foundations
● Blockchain Internal Working
● Ethereum and it’s Ecosystem
● Solana client side apps
● Smart Contracts
● Solidity from Basic to Advance
● Rust Basic to Advance
● Advance Projects with Deployment
มุมมอง: 12 579
วีดีโอ
House Robber | House Robber 2
มุมมอง 11K3 หลายเดือนก่อน
This is the fourth video of Dynamic Programming, we are starting from basic to build the foundation and will slowly move to advance problems. 1: House Robber : leetcode.com/problems/house-robber/description/ 2: House Robber 2: leetcode.com/problems/house-robber-ii/description/ Buy Course link: rohittnegi.akamai.net.in/new-courses/4-web-development-block-chain Play store app of Coder Army: play....
Count number of hops | Min Cost Climbing Stairs
มุมมอง 4.3K3 หลายเดือนก่อน
This is the third video of Dynamic Programming, we are starting from basic to build the foundation and will slowly move to advance problems. 1: Count Hops: www.geeksforgeeks.org/problems/count-number-of-hops-1587115620/1?page=1&difficulty[]=0&category[]=Dynamic%20Programming&sortBy=submissions 2: Min Cost Climbing Stairs: leetcode.com/problems/min-cost-climbing-stairs/description/ Buy Course li...
Climbing Stairs | Dynamic Programming
มุมมอง 6K3 หลายเดือนก่อน
This is the first video of Dynamic Programming, we are starting from basic to build the foundation and will slowly move to advance problems. 1: Climbing Stairs: leetcode.com/problems/climbing-stairs/description/ 2: Count Hops: www.geeksforgeeks.org/problems/count-number-of-hops-1587115620/1?page=1&difficulty[]=0&category[]=Dynamic%20Programming&sortBy=submissions Buy Course link: rohittnegi.aka...
Introduction To Dynamic Programming
มุมมอง 14K3 หลายเดือนก่อน
This is the first video of Dynamic Programming, we are starting from basic to build the foundation and will slowly move to advance problems. Fibonacci : leetcode.com/problems/fibonacci-number/ Buy Course link: rohittnegi.akamai.net.in/new-courses/4-web-development-block-chain Play store app of Coder Army: play.google.com/store/apps/details?id=com.rohit.negi Coupon Code: CODER ARMY Buy Course at...
Launching Live WEB Development and WEB3 Course | NEXUS
มุมมอง 14K3 หลายเดือนก่อน
We have Launched a Live course on Web Development (MERN Stack) and Blockchain, where we are going to cover each and everything from basic to Advance level. There is no prerequisite of the course. Buy Course link: rohittnegi.akamai.net.in/new-courses/4-web-development-block-chain Play store app of Coder Army: play.google.com/store/apps/details?id=com.rohit.negi Coupon Code: CODER ARMY Buy Course...
Hashing in Data Structure | Zero To Advance Level
มุมมอง 24K4 หลายเดือนก่อน
Hash Functions | Hash Collisions | Separate Chaining | Linear Probing, Quadratic Probing, Double Hashing | Cryptography | Load Factor and Rehashing | How maps work in C 00:00 Introduction 00:47 Understanding Hashing 5:35 Understanding Concept using a Question 12:32 Solving Problems in Hash Function, Hash Collision 16:04 Method 1 - Separate Chaining for collision 21:58 Method 2 - Linear Probing ...
Launching Free Dynamic Programming , Trie and Segment Tree Course
มุมมอง 11K4 หลายเดือนก่อน
We have launched Free Course on Dynamic Programming, Trie and Segment Tree. You can access it for free through our app. Install our app: Coder Army (Android) Link: play.google.com/store/apps/details?id=com.rohit.negi
Greedy Algorithm From Basic To Advance
มุมมอง 25K4 หลายเดือนก่อน
Recursion BackTracking #dsa #graph #datastructure What is Graphs in DSA and why do we need it. We talked about it with the help of real world example and it will help everyone to get command over graphs. Day 26/60 of challenge..... 1: Minimum number of Coins: www.geeksforgeeks.org/problems/-minimum-number-of-coins4426/1?itm_source=geeksforgeeks&itm_medium=article&itm_campaign=bottom_sticky_on_a...
BackTracking: N-Queens | M-Coloring Problem | Sudoku Solver
มุมมอง 12K5 หลายเดือนก่อน
Recursion BackTracking #dsa #graph #datastructure What is Graphs in DSA and why do we need it. We talked about it with the help of real world example and it will help everyone to get command over graphs. Day 25/60 of challenge..... 1: N-Queens: leetcode.com/problems/n-queens/ 2: M-Coloring Problem: www.geeksforgeeks.org/problems/m-coloring-problem-1587115620/1 3: Sudoku Solver: leetcode.com/pro...
Strongly Connected Components | Kosaraju Algorithm | Tarjan Algorithm
มุมมอง 7K5 หลายเดือนก่อน
Graph Data Structure | Graph Theory | Graph in DSA #dsa #graph #datastructure What is Graphs in DSA and why do we need it. We talked about it with the help of real world example and it will help everyone to get command over graphs. Day 24/60 of challenge..... 1: Kosaraju's Algo: www.geeksforgeeks.org/problems/strongly-connected-components-kosarajus-algo/1 2: (Tarjans's Algo: www.geeksforgeeks.o...
Hamiltonian Path | Hamiltonian Cycle
มุมมอง 3.9K5 หลายเดือนก่อน
Graph Data Structure | Graph Theory | Graph in DSA #dsa #graph #datastructure What is Graphs in DSA and why do we need it. We talked about it with the help of real world example and it will help everyone to get command over graphs. Day 23/60 of challenge..... 1: Hamiltonian Path: www.geeksforgeeks.org/problems/hamiltonian-path2522/1 Video will come on Mon-Fri at 6am in the morning DSA Course fo...
Articulation Point in a Graph | Tarjan's Algorithm
มุมมอง 4.3K5 หลายเดือนก่อน
Graph Data Structure | Graph Theory | Graph in DSA #dsa #graph #datastructure What is Graphs in DSA and why do we need it. We talked about it with the help of real world example and it will help everyone to get command over graphs. Day 22/60 of challenge..... 1: Articulation Point: www.geeksforgeeks.org/problems/articulation-point-1/1 Video will come on Mon-Fri at 6am in the morning DSA Course ...
Bridge in a Graph | Critical Connections in a Network
มุมมอง 6K5 หลายเดือนก่อน
Graph Data Structure | Graph Theory | Graph in DSA #dsa #graph #datastructure What is Graphs in DSA and why do we need it. We talked about it with the help of real world example and it will help everyone to get command over graphs. Day 21/60 of challenge..... 1: Critical Connections in a Network: leetcode.com/problems/critical-connections-in-a-network/description/ Video will come on Mon-Fri at ...
Minimum Spanning Tree | Prim’s Algorithm
มุมมอง 8K5 หลายเดือนก่อน
Minimum Spanning Tree | Prim’s Algorithm
Euler Path and Euler Circuit in a Graph
มุมมอง 5K6 หลายเดือนก่อน
Euler Path and Euler Circuit in a Graph
Graphs: Knight Walk | Shortest Source to Destination Path in Binary Matrix | Find whether path exist
มุมมอง 4.6K6 หลายเดือนก่อน
Graphs: Knight Walk | Shortest Source to Destination Path in Binary Matrix | Find whether path exist
Floyd Warshall Algorithm | MultiSource Shortest Path Algorithm
มุมมอง 8K6 หลายเดือนก่อน
Floyd Warshall Algorithm | MultiSource Shortest Path Algorithm
Bellman-Ford Algorithm | Distance from the Source
มุมมอง 7K6 หลายเดือนก่อน
Bellman-Ford Algorithm | Distance from the Source
Shortest Path in Weighted undirected graph
มุมมอง 6K6 หลายเดือนก่อน
Shortest Path in Weighted undirected graph
Dijkstra Algorithm | Intuition + Code + Dry Run + 2 Methods
มุมมอง 11K6 หลายเดือนก่อน
Dijkstra Algorithm | Intuition Code Dry Run 2 Methods
Graphs: Shortest Path in Directed Acyclic Graph
มุมมอง 7K6 หลายเดือนก่อน
Graphs: Shortest Path in Directed Acyclic Graph
Graph: Shortest Path in Undirected Graph
มุมมอง 7K6 หลายเดือนก่อน
Graph: Shortest Path in Undirected Graph
Graphs: Alien Dictionary | Parallel Courses 3 | Course Schedule | Prerequisite Tasks
มุมมอง 8K6 หลายเดือนก่อน
Graphs: Alien Dictionary | Parallel Courses 3 | Course Schedule | Prerequisite Tasks
Graphs: Covid Spread | Find the number of Islands | Replace O's with X's
มุมมอง 9K6 หลายเดือนก่อน
Graphs: Covid Spread | Find the number of Islands | Replace O's with X's
Bipartite Graph | BFS + DFS + Code + Real Life application
มุมมอง 8K6 หลายเดือนก่อน
Bipartite Graph | BFS DFS Code Real Life application
Amazing lecture Bhaiya
I have always learned everything by myself through documentation and solving questions, such as HTML, CSS, JavaScript, and Java basic. I never learned from TH-cam because the long, boring lectures didn’t match my vibe or understanding, and they lacked real-world examples for each topic. However, I heard from my peers on LinkedIn that this is a great channel for learning and it is... after saw his explaination on array video. I'm currently started C++ Journey from basic to advanced!
Radhe Radhe
❤
Last tk
This Single video is enough for stack
Chamak gaiya ❤
SOLUTION FOR MERGE TWO BST USING STACK: class Solution { public: // Function to return a list of integers denoting the node // values of both the BST in a sorted order. void fill(Node*root,stack<Node*>&s){ if(!root) return NULL; s.push(root); fill(root->left,s); } vector<int> merge(Node *root1, Node *root2) { stack<Node*>s1; stack<Node*>s2; vector<int>ans; fill(root1,s1); fill(root2,s2); while(!s1.empty() && !s2.empty()){ if(s1.top()->data<s2.top()->data){ ans.push_back(s1.top()->data); Node*temp=s1.top()->right; s1.pop(); fill(temp,s1); } else if(s1.top()->data>s2.top()->data){ ans.push_back(s2.top()->data); Node*temp=s2.top()->right; s2.pop(); fill(temp,s2); } else{ ans.push_back(s1.top()->data); ans.push_back(s2.top()->data); Node*temp1=s1.top()->right; Node*temp2=s2.top()->right; s1.pop(); s2.pop(); fill(temp1,s1); fill(temp2,s2); } } while(!s1.empty()){ ans.push_back(s1.top()->data); Node*temp=s1.top()->right; s1.pop(); fill(temp,s1); } while(!s2.empty()){ ans.push_back(s2.top()->data); Node*temp=s2.top()->right; s2.pop(); fill(temp,s2); } return ans; } };
❤❤
now the mathematical proof shines like sun.. 🌞
Day 29 completed [ 22/12/2024; 2250 IST].
Day 30 completed [ 23/12/2024; 1442 IST].
excellent
Bro thanks
Best video of dp
Common sense++
Thanks bro🙏🙏
alhamdulillah lec done awesome vaiya
whole video is best!!
Chamak gya❤
Chamak diya
Day 4
Common sense ++++
graph++😍😍
First Question can be done using 2 loops only for(int row=1;row<=n;row++) { for(int col=1;col<=n;col++) { if(col<=n-row) { cout << " "; }else { cout << "* "; } } cout << endl; }
Bhaiya pura code kiya kijiye hmm samajh nahi pate hai
Full stack web development kra do bhaiya.hum ap ky intezar ma bethy han 😢.
sir aap ke akhri alfazo ne sad kr diya
This lecture is Sooooooooooooooooooooooooooooooooooooooooooooooo good and really incredible.
Finally I understand dynamic and static memory allocation.Thank you sir .❤❤❤❤❤
Great sir❤❤❤❤
Day 3
SOLUTION FOR PROBLEM 3: class Solution{ public: void BST(Node*root,stack<int>&lower,stack<int>&upper,bool&check){ if(!root) return ; if(root->data>lower.top() && root->data<upper.top()){ upper.push(root->data); } if(!root->left && !root->right){ if(upper.top()-lower.top()==1){ lower.push(upper.top()); upper.pop(); if(upper.top()-lower.top()==1) check=true; upper.push(lower.top()); lower.pop(); } } BST(root->left,lower,upper,check); lower.push(upper.top()); upper.pop(); BST(root->right,lower,upper,check); } bool isDeadEnd(Node *root) { stack<int>lower; stack<int>upper; lower.push(0); upper.push(INT_MAX); bool check=false; BST(root,lower,upper,check); return check; } };
Love from Pakistan bro... Complete Pakistan watching educational videos of Indian youtubers
47:50 Rotated By 1(New Approach) => Time complexity of the rotation algorithm is O(n), and the space complexity is O(1). public class Main { public static void rev(int[] arr, int s, int e){ while(s < e){ int t = arr[s]; arr[s] = arr[e]; arr[e] = t; s++; e--; } } public static void printArr(int[] a){ for(int e : a){ System.out.print(e + " "); } } public static void main(String[] args) { int a[] = {2,7,4,11,5,8}; System.out.println("Without Rotation: "); printArr(a); int roteteBy = 1; rev(a, 0, a.length-roteteBy-1); rev(a, a.length-roteteBy, a.length-1); rev(a, 0, a.length-1); System.out.println(); System.out.println("After Rotation: "); printArr(a); } }
Ha bhai ye concept aashe se samajh me aagaya. It was really amazing. I am getting a lot from your these series+
22 dec'24
Radhe Radhe 🕉️🦚
Chamak gya ✨✨✨
SOLUTION FOR LCA: class Solution{ public: Node* LCA(Node *root, int n1, int n2) { Node*lowest; while(root->data!=n1 || root->data!=n2){ lowest=root; if(root->data<n1 && root->data<n2) root=root->right; else if(root->data>n1 && root->data>n2) root=root->left; else return lowest; } return root; } };
This is really great stack series. Thank you bhaiya❤
Thanks sir❤
solution of the lecture end H.W:- class Solution { public: // Function to sort a linked list of 0s, 1s and 2s. Node* segregate(Node* head) { Node *head0 = NULL,*tail0 = NULL; Node *head1 = NULL,*tail1 = NULL; Node *head2 = NULL,*tail2 = NULL; while(head) { if(head->data == 0) { if(head0 == NULL) { head0 = new Node(head->data); tail0 = head0; } else { Node *temp; temp = new Node(head->data); tail0->next = temp; tail0 = temp; } } else if(head->data == 1) { if(head1 == NULL) { head1 = new Node(head->data); tail1 = head1; } else { Node *temp; temp = new Node(head->data); tail1->next = temp; tail1 = temp; } } else { if(head2 == NULL) { head2 = new Node(head->data); tail2 = head2; } else { Node *temp; temp = new Node(head->data); tail2->next = temp; tail2 = temp; } } head = head->next; } if(head0) { if(head1) { tail0->next = head1; if(head2) { tail1->next = head2; } } else { tail0->next = head2; } return head0; } else if(head1) { tail1->next = head2; return head1; } return head2; } };
SOLUTION FOR QUESTION NO. 3 USING STACK: class Solution { public: int canRepresentBST(int arr[], int N) { stack<int>lower; stack<int>upper; lower.push(INT_MIN); upper.push(INT_MAX); int index=0; while(index<N && !lower.empty() && !upper.empty()){ if(arr[index]>lower.top() && arr[index]<upper.top()){ upper.push(arr[index++]); } else{ lower.push(upper.top()); upper.pop(); } } if(index==N) return 1; else return 0; } };
int count(int i,int n){ if(i==n) return 1; if(i>n) return 0; return count(i+1,n) + count(i+2,n) + count(i+3,n); } // Function to count the number of ways in which frog can reach the top. int countWays(int n) { // your code here return count(0,n); }
//Bruteforce Approach class Solution { public ArrayList<Integer> maxOfMin(int[] arr) { ArrayList<Integer> result = new ArrayList<>(); for (int windowSize = 1; windowSize <= arr.length; windowSize++) { result.add(maxOfMinInWindow(windowSize, arr)); } return result; } private int maxOfMinInWindow(int k, int[] arr) { int maxOfMin = Integer.MIN_VALUE; // Iterate over all possible windows of size k for (int i = 0; i <= arr.length - k; i++) { int currentMin = Integer.MAX_VALUE; // Find the minimum in the current window for (int j = i; j < i + k; j++) { currentMin = Math.min(currentMin, arr[j]); } // Update the maximum of the minimums maxOfMin = Math.max(maxOfMin, currentMin); } return maxOfMin; } } //Better Approach (Using monotonic increasing deque) class Solution { public ArrayList<Integer> maxOfMin(int[] arr) { ArrayList<Integer> result = new ArrayList<>(); for (int windowSize = 1; windowSize <= arr.length; windowSize++) { result.add(maxOfMinInWindow(windowSize, arr)); } return result; } private int maxOfMinInWindow(int k, int[] arr) { Deque<Integer> deque = new ArrayDeque<>(); int maxOfMin = Integer.MIN_VALUE; // Process the first window separately for (int i = 0; i < k; i++) { // Maintain a monotonic increasing deque where the smallest element is always at the front while (!deque.isEmpty() && arr[deque.peekLast()] >= arr[i]) { deque.pollLast(); } deque.offerLast(i); } // The front of the deque is the minimum of the 1st window maxOfMin = Math.max(maxOfMin, arr[deque.peekFirst()]); // Process the remaining windows for (int windowEndIndex = k; windowEndIndex < arr.length; windowEndIndex++) { // Maintain the deque for the current window while (!deque.isEmpty() && arr[deque.peekLast()] >= arr[windowEndIndex]) { deque.pollLast(); } deque.offerLast(windowEndIndex); // Remove element from the deque if the maximum no longer belongs to the current window, i.e., it belongs to the previous window. if (!deque.isEmpty() && deque.peekFirst() <= windowEndIndex - k) { deque.pollFirst(); } // The front of the deque is the minimum of the current window maxOfMin = Math.max(maxOfMin, arr[deque.peekFirst()]); } return maxOfMin; } } //Optimal Approach //Naive Implementation class Solution { private Deque<Integer> stack; public ArrayList<Integer> maxOfMin(int[] arr) { stack = new ArrayDeque<>(); ArrayList<Integer> maxOfMinForWindowSizes = new ArrayList<>(Collections.nCopies(arr.length, 0)); // Find previous and next smaller element indices int[] pseIndex = findNextSmallerOnLeft(arr); stack.clear(); int[] nseIndex = findNextSmallerOnRight(arr); for (int i = 0; i < arr.length; i++) { /* * The window span represents the range of window sizes where the current * element is a candidate for the minimum element. Specifically, it means this element * can be the minimum for windows of size 1 to `windowSpan`. */ int windowSpan = nseIndex[i] - pseIndex[i] - 1; maxOfMinForWindowSizes.set(windowSpan - 1, Math.max(maxOfMinForWindowSizes.get(windowSpan - 1), arr[i])); } /* * Instead of updating all candidate windows for each element, we only update the * answer array for the largest possible window size (`windowSpan`) in which * the current element can be the minimum. This avoids unnecessary O(n²) time complexity * by restricting updates to only the largest valid window size for each element. * * After processing all elements, we perform a second pass from the * second-largest window size down to propagate the maximum values. This ensures that the * answer for any smaller window size also takes into account the maximum value of the * corresponding larger window size: * - For a window of size `i`, the answer will be the maximum between the current * value for window size `i` and the value for window size `i+1`. * - This works because an element valid for a larger window (`i+1`) is also * valid for any smaller window (`i`). * * This optimization allows us to build the result in O(n) time after the * initial pass, efficiently utilizing the fact that larger window candidates also apply to smaller ones. */ /* * The reason we start updating from `n-2` (processing window sizes from the second-largest downwards) * is that for a window size of `n` (the entire array), there is only one possible window-the array itself. * * For this single window, the smallest element is guaranteed to be the overall * minimum of the entire array, and this value directly contributes to the result for the window size `n`, * so it is already correctly computed. * * Additionally, for a window of size `n`, there will always be exactly one candidate element * (possibly repeated) that will be the minimum for a window of size `n`. */ for (int i = arr.length - 2; i >= 0; i--) { maxOfMinForWindowSizes.set(i, Math.max(maxOfMinForWindowSizes.get(i), maxOfMinForWindowSizes.get(i + 1))); } return maxOfMinForWindowSizes; } private int[] findNextSmallerOnLeft(int[] arr) { int[] pseIndex = new int[arr.length]; for (int i = 0; i < arr.length; i++) { while (!stack.isEmpty() && arr[stack.peek()] >= arr[i]) { stack.pop(); } pseIndex[i] = stack.isEmpty() ? -1 : stack.peek(); stack.push(i); } return pseIndex; } private int[] findNextSmallerOnRight(int[] arr) { int[] nseIndex = new int[arr.length]; for (int i = arr.length - 1; i >= 0; i--) { while (!stack.isEmpty() && arr[stack.peek()] >= arr[i]) { stack.pop(); } nseIndex[i] = stack.isEmpty() ? arr.length : stack.peek(); stack.push(i); } return nseIndex; } } //Better Implementation class Solution { private Deque<Integer> stack; public ArrayList<Integer> maxOfMin(int[] arr) { stack = new ArrayDeque<>(); ArrayList<Integer> maxOfMinForWindowSizes = new ArrayList<>(Collections.nCopies(arr.length, 0)); int[] nseIndex = findNextSmallerOnRight(arr); stack.clear(); for (int i = 0; i < arr.length; i++) { while (!stack.isEmpty() && arr[stack.peek()] >= arr[i]) { stack.pop(); } int pseIndex = stack.isEmpty() ? -1 : stack.peek(); int windowSpan = nseIndex[i] - pseIndex - 1; maxOfMinForWindowSizes.set(windowSpan - 1, Math.max(maxOfMinForWindowSizes.get(windowSpan - 1), arr[i])); stack.push(i); } for (int i = arr.length - 2; i >= 0; i--) { maxOfMinForWindowSizes.set(i, Math.max(maxOfMinForWindowSizes.get(i), maxOfMinForWindowSizes.get(i + 1))); } return maxOfMinForWindowSizes; } private int[] findNextSmallerOnRight(int[] arr) { int[] nseIndex = new int[arr.length]; for (int i = arr.length - 1; i >= 0; i--) { while (!stack.isEmpty() && arr[stack.peek()] >= arr[i]) { stack.pop(); } nseIndex[i] = stack.isEmpty() ? arr.length : stack.peek(); stack.push(i); } return nseIndex; } } //Optimal Implementation class Solution { public ArrayList<Integer> maxOfMin(int[] arr) { Deque<Integer> stack = new ArrayDeque<>(); ArrayList<Integer> maxOfMinForWindowSizes = new ArrayList<>(Collections.nCopies(arr.length, 0)); for (int i = 0; i < arr.length; i++) { while (!stack.isEmpty() && arr[stack.peek()] >= arr[i]) { int index = stack.pop(); int previousSmallerElementIndex = stack.isEmpty() ? -1 : stack.peek(); int nextSmallerElementIndex = i; int windowSpan = nextSmallerElementIndex - previousSmallerElementIndex - 1; maxOfMinForWindowSizes.set(windowSpan - 1, Math.max(maxOfMinForWindowSizes.get(windowSpan - 1), arr[index])); } stack.push(i); } while (!stack.isEmpty()) { int index = stack.pop(); int previousSmallerElementIndex = stack.isEmpty() ? -1 : stack.peek(); int nextSmallerElementIndex = arr.length; int windowSpan = nextSmallerElementIndex - previousSmallerElementIndex - 1; maxOfMinForWindowSizes.set(windowSpan - 1, Math.max(maxOfMinForWindowSizes.get(windowSpan - 1), arr[index])); } for (int i = arr.length - 2; i >= 0; i--) { maxOfMinForWindowSizes.set(i, Math.max(maxOfMinForWindowSizes.get(i), maxOfMinForWindowSizes.get(i + 1))); } return maxOfMinForWindowSizes; } }
❤❤
Chamak Gya Bhaiya... class Solution { public: // Function to remove a loop in the linked list. void removeLoop(Node* head) { // just remove the loop without losing any nodes // making a map and then iterating trough each node while taking the node of their addresses // if we encounter the same address again then there is a loop otherwise // we don't have to do any thing .. unordered_map<Node*,bool>visited; // we take two pointers front and prev and move front and previous point to just prev // node from the front pointer .. Node*front = head,*prev = NULL; while(front){ if(visited[front]==true){ prev->next = NULL; return; } else{ visited[front] =true; prev = front; } // move the front pointer to the next node.. front = front->next; } } };
hanjii ji cleear h
❤