Given a binary array, task is to sort this binary array using minimum swaps. We are allowed to swap only adjacent elementsContinue reading “[Challenge]Minimum adjacent swaps required to Sort Binary array”
Given a list of non negative integers, arrange them such that they form the largest number.Continue reading “[Leetcode]179. Largest Number”
You are given an n x n 2DContinue reading “[Leetcode]48. Rotate Image”
matrixrepresenting an image, rotate the image by 90 degrees (clockwise). You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.
We have an array of integers,Continue reading “[Leetcode]1589. Maximum Sum Obtained of Any Permutation”
nums, and an array of
requests[i] = [starti, endi]. The
ithrequest asks for the sum of
nums[starti] + nums[starti + 1] + ... + nums[endi - 1] + nums[endi]. Both
endiare 0-indexed. Return the maximum total sum of all requests among all permutations of
nums. Since the answer may be too large, return it modulo
109 + 7.
Given an array of positive integersContinue reading “[Leetcode]1590. Make Sum Divisible by P”
nums, remove the smallest subarray (possibly empty) such that the sum of the remaining elements is divisible by
p. It is not allowed to remove the whole array. Return the length of the smallest subarray that you need to remove, or
-1if it's impossible. A subarray is defined as a contiguous block of elements in the array.
You are given an integer arrayContinue reading “[Leetcode]33. Search in Rotated Sorted Array”
numssorted in ascending order, and an integer
target. Suppose that
numsis rotated at some pivot unknown to you beforehand (i.e.,
targetis found in the array return its index, otherwise, return
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum result of ai XOR aj, where 0 ≤ i, j < n. Could you do this in O(n) runtime?Continue reading “[Leetcode]421. Maximum XOR of Two Numbers in an Array”
Continue reading “Disjoint Set – Union & Find”
In computer science, a disjoint-set data structure … is a data structure that stores a collection of disjoint (non-overlapping) sets. … It provides operations for adding new sets, merging sets (replacing them by their union), and finding a representative member of a set.Source: https://en.wikipedia.org/wiki/Disjoint-set_data_structure