2058. Find the Minimum and Maximum Number of Nodes Between Critical Points | DSA | Hindi
HTML-код
- Опубликовано: 22 авг 2024
- Problem:
2058. Find the Minimum and Maximum Number of Nodes Between Critical Points
Problem Statement:
A critical point in a linked list is defined as either a local maxima or a local minima.
A node is a local maxima if the current node has a value strictly greater than the previous node and the next node.
A node is a local minima if the current node has a value strictly smaller than the previous node and the next node.
Note that a node can only be a local maxima/minima if there exists both a previous node and a next node.
Given a linked list head, return an array of length 2 containing [minDistance, maxDistance] where minDistance is the minimum distance between any two distinct critical points and maxDistance is the maximum distance between any two distinct critical points. If there are fewer than two critical points, return [-1, -1].
Problem Link:
leetcode.com/p...
Graph Playlist:
• Graph Data Structure S...
Java Plus DSA Placement Course Playlist:
• Java and DSA Course Pl...
Java Plus DSA Sheet:
docs.google.co...
Notes:
github.com/Tiw...
Telegram Link:
shashwattiwari...
Ultimate Recursion Series Playlist:
• Recursion and Backtrac...
Instagram Handle: (@shashwat_tiwari_st)
shashwattiwari...
Samsung Interview Experience:
• I cracked Samsung | SR...
Company Tags:
Facebook | Amazon | Microsoft | Netflix | Google | LinkedIn | Pega Systems | VMware | Adobe | Samsung
Timestamp:
0:00 - Introduction
#ShashwatTiwari #coding #problemsolving
like target for this video is 80. Please do like if you understood the solution😄
op bhaiya, aaj ka khud krliya tha, almost same approach bs aapka code kafi neat hai mere se😅😅
Thanks 😊 , today I approached the problem same you did.
thankyou so much sir ❤❤❤❤❤❤❤❤
One of best explanation
Thank you ! Today i solved these on my own😊
Love from usa❤
slow aur acha padhate ho jisse dsa ke question easy lagne laga
thank you so much for making this video
great work can you also make development related videos
hi sir, I am from upes!!
Hello there!
great
I had solved but the!!!!....🥲🥲
the time complexity of the solution is O(N + K log K)
import java.util.ArrayList;
import java.util.Collections;
class ListNode {
int val;
ListNode next;
ListNode(int x) { val = x; }
}
class Solution {
public int[] nodesBetweenCriticalPoints(ListNode head) {
// Step 1: Convert linked list to array and determine size
ListNode current = head;
int size = 0;
ArrayList values = new ArrayList();
while (current != null) {
values.add(current.val);
current = current.next;
size++;
}
// Step 2: Handle edge case for size values.get(j) && values.get(j) < values.get(j + 1)) {
mini.add(j);
}
}
ArrayList result = new ArrayList();
result.addAll(maxi);
result.addAll(mini);
Collections.sort(result);
int[] arr = new int[result.size()];
for (int i = 0; i < result.size(); i++) {
arr[i] = result.get(i);
}
if (arr.length >= 2) {
int minDiff = Integer.MAX_VALUE;
// Find the minimum difference
for (int i = 1; i < arr.length; i++) {
int diff = arr[i] - arr[i - 1];
if (diff < minDiff) {
minDiff = diff;
}
}
// Find the maximum difference
int maxDiff = arr[arr.length - 1] - arr[0];
return new int[] {minDiff, maxDiff};
} else {
return new int[] {-1, -1};
}
}
}
Please explain this question again unable to understand 🙏🏻
you have seen linked list playlist ? If no, please watch that first, because you should know, linked list traversal well and then only solve problems.