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​

Комментарии • 16

  • @shashwat_tiwari_st
    @shashwat_tiwari_st  Месяц назад +7

    like target for this video is 80. Please do like if you understood the solution😄

  • @PiyushSharma-we8yd
    @PiyushSharma-we8yd Месяц назад +2

    op bhaiya, aaj ka khud krliya tha, almost same approach bs aapka code kafi neat hai mere se😅😅

  • @RohitKumar-dz8dh
    @RohitKumar-dz8dh Месяц назад +2

    Thanks 😊 , today I approached the problem same you did.

  • @kunalsarpal7564
    @kunalsarpal7564 Месяц назад +1

    thankyou so much sir ❤❤❤❤❤❤❤❤

  • @varadpanchal1231
    @varadpanchal1231 Месяц назад

    One of best explanation

  • @ankitagrawal4477
    @ankitagrawal4477 Месяц назад

    Thank you ! Today i solved these on my own😊

  • @GirjeshSharma-zv3xo
    @GirjeshSharma-zv3xo Месяц назад +1

    Love from usa❤

  • @Nishant89-i2z
    @Nishant89-i2z Месяц назад

    slow aur acha padhate ho jisse dsa ke question easy lagne laga

  • @deluluvish
    @deluluvish Месяц назад +1

    thank you so much for making this video

  • @sankalpbarriar1029
    @sankalpbarriar1029 Месяц назад +1

    great work can you also make development related videos

  • @aggarwalsachin4854
    @aggarwalsachin4854 Месяц назад +1

    hi sir, I am from upes!!

  • @user-oi5ls4rs5g
    @user-oi5ls4rs5g Месяц назад +1

    great

  • @ashwinmali4338
    @ashwinmali4338 Месяц назад

    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};
    }
    }
    }

  • @GirjeshSharma-zv3xo
    @GirjeshSharma-zv3xo Месяц назад +1

    Please explain this question again unable to understand 🙏🏻

    • @shashwat_tiwari_st
      @shashwat_tiwari_st  Месяц назад

      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.