ZHR Blog

For those who fight for it, life has a flavor the sheltered will never know

Partition Array into Disjoint Intervals

Leetcode Daily Challenge

Problem Given an array nums, partition it into two (contiguous) subarrays left and right so that: Every element in left is less than or equal to every element in right. left and right are non-empt...

Push Dominoes

Leetcode Daily Challenge

Problem There are n dominoes in a line, and we place each domino vertically upright. In the beginning, we simultaneously push some of the dominoes either to the left or to the right. After each se...

Shuffle an Array

Leetcode Daily Challenge

Problem Given an integer array nums, design an algorithm to randomly shuffle the array. All permutations of the array should be equally likely as a result of the shuffling. Implement the Solution ...

Lowest Common Ancestor of a Binary Search Tree

Leetcode Daily Challenge

Problem Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikipedia: “The lowest common ancestor is defin...

Reverse Nodes in k group

Leetcode Daily Challenge

Problem Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k is a positive integer and is less than or equal to the length of the linked list. If the...

Three Equal Part

Leetcode Daily Challenge

Problem You are given an array arr which consists of only zeros and ones, divide the array into three non-empty parts such that all of these parts represent the same binary value. If it is possibl...

4Sum

Leetcode Daily Challenge

Problem Given an array nums of n integers, return an array of all the unique quadruplets [nums[a], nums[b], nums[c], nums[d]] such that: 0 <= a, b, c, d < n a, b, c, and d are distinct. nums...

Valid Triangle Number

Leetcode Daily Challenge

Problem Given an integer array nums, return the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle. Constraints 1 <= nums.length <...

Range Addition

Leetcode Daily Challenge

Problem You are given an integer length and an array updates where updates[i] = [startIdxi, endIdxi, inci]. You have an array arr of length length with all zeros, and you have some operation to ap...

Custom Sort String

Leetcode Daily Challenge

Problem order and str are strings composed of lowercase letters. In order, no letter occurs more than once. order was sorted in some custom order previously. We want to permute the characters of s...