Leetcode 0033. Search in Rotated Sorted Array

Posted on Wed 11 December 2024 in Leetcode • Tagged with binary-search

Question Link : https://leetcode.com/problems/search-in-rotated-sorted-array/

Difficulty: Medium

Premium: False

Question

There is an integer array nums sorted in ascending order (with distinct values). Prior to being passed to your function, nums is possibly rotated at an unknown pivot index k (1 <= k < nums.length) such that the resulting …


Continue reading

Leetcode 0034. Find First and Last Position of Element in Sorted Array

Posted on Wed 11 December 2024 in Leetcode • Tagged with binary-search

Question Link : https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/

Difficulty: Medium

Premium: False

Question

Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value. If target is not found in the array, return [-1, -1]. You must write an algorithm with …


Continue reading

Leetcode 0035. Search Insert Position

Posted on Wed 11 December 2024 in Leetcode • Tagged with binary-search

Question Link : https://leetcode.com/problems/search-insert-position/

Difficulty: Easy

Premium: False

Question

Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You must write an …


Continue reading

Leetcode 0278. First Bad Version

Posted on Wed 11 December 2024 in Leetcode • Tagged with binary-search

Question Link : https://leetcode.com/problems/first-bad-version/

Difficulty: Easy

Premium: False

Question

You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the …


Continue reading

Leetcode 0704. Binary Search

Posted on Wed 11 December 2024 in Leetcode • Tagged with binary-search

Question Link : https://leetcode.com/problems/binary-search/

Difficulty: Easy

Premium: False

Question

Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1. You must write an …


Continue reading

Leetcode 1891. Cutting Ribbons

Posted on Sun 08 December 2024 in Leetcode Premium • Tagged with binary-search

Question Link : https://leetcode.com/problems/cutting-ribbons/

Difficulty: Medium

Premium: True

Question

You are given an integer array ribbons, where ribbons[i] represents the length of the ith ribbon, and an integer k. You may cut any of the ribbons into any number of segments of positive integer lengths, or …


Continue reading

Leetcode 0270. Closest Binary Search Tree Value

Posted on Fri 22 November 2024 in Leetcode Premium • Tagged with bst, binary-search

Question Link : https://leetcode.com/problems/closest-binary-search-tree-value/

Difficulty: Easy

Premium: True

Question

Given the root of a binary search tree and a target value, return the value in the BST that is closest to the target. If there are multiple answers, print the smallest.   Example 1:

Input: root = [4,2 …


Continue reading

Leetcode 2389. Longest Subsequence With Limited Sum

Posted on Fri 22 November 2024 in Leetcode • Tagged with subset-sum, binary-search

Question Link : https://leetcode.com/problems/longest-subsequence-with-limited-sum/

Difficulty: Easy

Premium: False

Question

You are given an integer array nums of length n, and an integer array queries of length m. Return an array answer of length m where answer[i] is the maximum size of a subsequence that you can …


Continue reading

Leetcode 2955. Number of Same-End Substrings

Posted on Fri 22 November 2024 in Leetcode Premium • Tagged with math, binary-search, prefix-sum

Question Link : https://leetcode.com/problems/number-of-same-end-substrings/

Difficulty: Medium

Premium: True

Question

You are given a 0-indexed string s, and a 2D array of integers queries, where queries[i] = [li, ri] indicates a substring of s starting from the index li and ending at the index ri (both inclusive), i …


Continue reading

Leetcode 0374. Guess Number Higher or Lower

Posted on Tue 15 November 2022 in Leetcode • Tagged with binary-search

Question Link : https://leetcode.com/problems/guess-number-higher-or-lower/

Difficulty: Easy

Question

We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I picked. Every time you guess wrong, I will tell you whether the number I …


Continue reading