Published in Towards Dev·3 days agoLeetCode — First Missing PositiveProblem statement — Given an unsorted integer array nums, return the smallest missing positive integer. You must implement an algorithm that runs in O(n) time and uses constant extra space. Problem statement taken from: https://leetcode.com/problems/first-missing-positive Example 1: Input: nums = [1, 2, 0] Output: 3 Explanation: The numbers in the range [1, 2] are all…Programming6 min readProgramming6 min read

Published in Towards Dev·5 days agoLeetCode — Reverse Nodes in k-GroupProblem statement — Given the head of a linked list, reverse the nodes of the list k at a time, and return the modified list. k is a positive integer and is less than or equal to the length of the linked list. …Programming6 min readProgramming6 min read

Published in Towards Dev·Mar 16LeetCode — Subarray Sum Equals KProblem statement — Given an array of integers nums and an integer k, return the total number of subarrays whose sum equals to k. A subarray is a contiguous non-empty sequence of elements within an array. Problem statement taken from: https://leetcode.com/problems/subarray-sum-equals-k Example 1: Input: nums = [1, 1, 1], k = 2 Output…Programming4 min readProgramming4 min read

Published in Towards Dev·Mar 9LeetCode — Reverse Words in a StringProblem statement — Given an input string s, reverse the order of the words. A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space. Return a string of the words in reverse order concatenated by a single space. Note that s…Programming7 min readProgramming7 min read

Published in Towards Dev·Mar 5LeetCode — Count Good Nodes in Binary TreeProblem statement — Given a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a value greater than X. Return the number of good nodes in the binary tree. Problem statement taken from: https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix Example 1: Input…Programming5 min readProgramming5 min read

Published in Towards Dev·Mar 4LeetCode — Kth Smallest Element in a Sorted MatrixProblem statement — Given an n x n matrix where each of the rows and columns is sorted in ascending order, return the kth smallest element in the matrix. Note that it is the kth smallest element in the sorted order, not the kth distinct element. You must find a solution with a…Programming8 min readProgramming8 min read

Published in Towards Dev·Feb 26LeetCode — Minimum Operations to Make Array EqualProblem statement You have an array arr of length n where arr[i] = (2 * i) + 1 for all valid values of i (i.e., 0 <= i < n). In one operation, you can select two indices x and y where 0 <= x, y < n and subtract 1 from…Leetcode4 min readLeetcode4 min read

Published in Towards Dev·Feb 19LeetCode — Minimize Maximum Pair Sum in ArrayProblem statement — The pair sum of a pair (a, b) is equal to a + b. The maximum pair sum is the largest pair sum in a list of pairs. For example, if we have pairs (1, 5), (2, 3), and (4, 4), the maximum pair sum would be max(1 + 5…Programming3 min readProgramming3 min read

Published in Towards Dev·Feb 18LeetCode — Difference Between Ones and Zeros in Row and ColumnProblem statement — You are given a 0-indexed m x n binary matrix grid. A 0-indexed m x n difference matrix diff is created with the following procedure: Let the number of ones in the ith row be onesRowi. Let the number of ones in the jth column be onesColj. Let the number…Programming7 min readProgramming7 min read

Published in Towards Dev·Feb 16LeetCode — Rearrange Array Elements by SignProblem statement You are given a 0-indexed integer array nums of even length consisting of an equal number of positive and negative integers. You should rearrange the elements of nums such that the modified array follows the given conditions: Every consecutive pair of integers have opposite signs. For all integers with the…Programming4 min readProgramming4 min read