Category Leetcode Solution

Single Number II LeetCode Solution

Problem – Single Number II LeetCode Solution Given an integer array nums where every element appears three times except for one, which appears exactly once. Find the single element and return it. You must implement a solution with a linear runtime complexity and use only constant extra space. Example 1:…

View Answers

Find Minimum in Rotated Sorted Array II LeetCode Solution

Problem – Find Minimum in Rotated Sorted Array II LeetCode Solution Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,4,4,5,6,7] might become: [4,5,6,7,0,1,4] if it was rotated 4 times. [0,1,4,4,5,6,7] if it was rotated 7 times. Notice that rotating an array [a[0], a[1], a[2],…

View Answers

Find Subarrays With Equal Sum LeetCode Solution

Problem – Find Subarrays With Equal Sum LeetCode Solution Given a 0-indexed integer array nums, determine whether there exist two subarrays of length 2 with equal sum. Note that the two subarrays must begin at different indices. Return true if these subarrays exist, and false otherwise. A subarray is a contiguous non-empty sequence of elements within an…

View Answers

Strictly Palindromic Number LeetCode Solution

Problem – Strictly Palindromic Number LeetCode Solution An integer n is strictly palindromic if, for every base b between 2 and n – 2 (inclusive), the string representation of the integer n in base b is palindromic. Given an integer n, return true if n is strictly palindromic and false otherwise. A string is palindromic if it reads the same forward and backward. Example 1: Example 2: Constraints:…

View Answers

Longest Nice Subarray LeetCode Solution

Problem – Longest Nice Subarray LeetCode Solution You are given an array nums consisting of positive integers. We call a subarray of nums nice if the bitwise AND of every pair of elements that are in different positions in the subarray is equal to 0. Return the length of the longest nice subarray. A subarray is a contiguous part…

View Answers

Check Distances Between Same Letters LeetCode Solution

Problem – Check Distances Between Same Letters LeetCode Solution You are given a 0-indexed string s consisting of only lowercase English letters, where each letter in s appears exactly twice. You are also given a 0-indexed integer array distance of length 26. Each letter in the alphabet is numbered from 0 to 25 (i.e. ‘a’ -> 0, ‘b’ ->…

View Answers

Maximum Number of Robots Within Budget LeetCode Solution

Problem – Maximum Number of Robots Within Budget LeetCode Solution You have n robots. You are given two 0-indexed integer arrays, chargeTimes and runningCosts, both of length n. The ith robot costs chargeTimes[i] units to charge and costs runningCosts[i] units to run. You are also given an integer budget. The total cost of running k chosen robots is equal…

View Answers