Home Arrays
Category:

Arrays

View algorithms on Arrays

  • ArraysStrings

    [Leetcode] – Word Break Solution

    by nikoo28
    4 minutes read

    In the given problem statement, we have a string s and a dictionary wordDict containing a list of words. We need to determine if s can be segmented into a space-separated sequence of dictionary words. The tricky part of this problem is ensuring that every segment of the string matches words from the dictionary. A brute-force approach could generate all possible segmentations, but that would be highly inefficient. Input: s = “studyalgorithms”wordDict = [“study”, “algorithms”]Output: trueExplanation: Since “studyalgorithms” can be split into “study” and “algorithms”, both of which are in …

    0 FacebookTwitterLinkedinWhatsappEmail
  • Arrays

    [Leetcode] – Insert Interval Solution

    by nikoo28
    4 minutes read

    In this problem, we are given a list of non-overlapping intervals sorted by their start times, along with a new interval. The goal is to insert the new interval into the list while ensuring the intervals remain non-overlapping and sorted. If necessary, overlapping intervals should be merged. The tricky part of this problem lies in handling overlapping intervals efficiently while maintaining the sorted order. We also need to consider edge cases, such as when the new interval does not overlap with any existing intervals or when it encompasses multiple intervals. …

    0 FacebookTwitterLinkedinWhatsappEmail
  • Always make sure that we understand the problem statement first. There is an array of integers nums and we need to determine the number of good pairs. A pair (i , j ) is said to be good, if nums[i] == nums[j] and i < j. We need to determine how many pairs can we form that hold this condition. Let us look at some sample test cases: Input: nums = [ 1 , 2 , 3 , 1 , 1 , 3 ]Output: 4Explanation:There are 4 good pairs. (0 …

    1 FacebookTwitterLinkedinWhatsappEmail
  • Arrays

    [Hackerrank] – Equal Solution

    by nikoo28
    6 minutes read

    Let us try to understand this problem statement first. It is actually very verbose. We will try to simplify it as much as possible. Christy wants to give chocolates to her colleagues, and at the same time tries to ensure that everyone has equal chocolates at the end. To achieve this she either gives 1,2, or 5 chocolates to everyone except any one individual. Every-time she does this, it is counted as 1 operation. We need to make sure that Christy can achieve this task in the minimum number of …

    2 FacebookTwitterLinkedinWhatsappEmail

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More