Showing 21 posts tagged with "leetcode"
2206. Divide Array Into Equal Pairs
In this article, we'll explain how to solve LeetCode problem 2206: Divide Array Into Equal Pairs. The problem asks us to determine if we can divide an array of $2n$ integers into $n$ pairs such that each element in a pa...
Apple Interview Loop: React Optimizations and the 2D Matrix Search
Recently, I went through a rigorous, multi-stage interview loop for a Front End Developer position at Apple (contracted via Mphasis). The process consisted of six rounds and required Sunnyvale relocation. It was a compr...
C++ Solution for LeetCode 2594. Minimum Time to Repair Cars
This article explains the solution for LeetCode 2594: Minimum Time to Repair Cars. Given mechanic ranks, where rank $r$ repairs $n$ cars in $r imes n^2$ minutes, we must find the minimum time needed to repair all cars....
2529. Maximum Count of Positive Integer and Negative Integer
So the daily leetcode challenge can be naively solved with a loop. But the best solution in the python category uses a built in method called bisect_left, so here is a binary search implementation of that method in Java...
2467. Most Profitable Path in a Tree
There is an undirected tree with n nodes labeled from 0 to n - 1, rooted at node 0. You are given a 2D integer array edges of length n - 1 where edges[i] = [ai, bi]...
Construct the Smallest Number
Developers flex on each with the strangest of ways. How green is your github commit history. Have you submitted a PR to a open source project. How well can you solve the silliest questions on leetcode / geeksforgeeks /...
Generating Subsets using Backtracking
1863. Sum of All Subset XOR TotalsThis is a good problem to grasp basics of backtracking The XOR total of an array is defined as the bitwise XOR of all its elements, or 0 if the array is empty. For example, the X...
LeetCode 1718. Construct the Lexicographically Largest Valid Sequence
This article explains the solution for LeetCode 1718: Construct the Lexicographically Largest Valid Sequence. Given an integer $n$, we want to construct a sequence of size $2n-1$ containing integers from $1$ to $n$ wher...
Find the Number of Distinct Colors Among the Balls
You are given an integer limit and a 2D array queries of size n x 2. There are limit + 1 balls with distinct labels in the range [0, limit]. Initially, all balls are...
Removing the Nth Node from a list.
https://leetcode.com/problems/remove-nth-node-from-end-of-list Given the head of a linked list, remove the nth node from the end of the list and return its head. Example 1: Input: head =...
Maximum Score After Splitting a String
Here is an explanation of the C++ solution for LeetCode 1422: Maximum Score After Splitting a String. The objective is to split a binary string s into two non-empty substrings (left and right) and find the maximum sum o...
90% of CS graduates can't figure this out
Someone important on X posted: https://x.com/vikhyatk/status/1873033432705712304 i have a very simple question i ask during phone screens: print each level of a tree on a separate line. 90% of CS grad candidates j...
Zigzag string conversion solution in C++
The Zigzag Conversion problem (LeetCode 6) asks us to write a string in a zigzag pattern across a given number of rows, and then read it row by row. Visualizing Zigzag Movement For numRows = 3: P A H N A P...
LeetCode 543 Diameter of a Binary Tree in C++
Given the root of a binary tree, return the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a...
401. Binary Watch
A binary watch has 4 LEDs on the top to represent the hours (0-11), and 6 LEDs on the bottom to represent the minutes (0-59). Each LED represents a zero or one, with the least significant bit on the right. For...
Letter Combinations of a phone number
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order. A mapping of digits to letters (just like o...
LeetCode 20 Valid Parentheses in Typescript
The mental challenge one might experience here is that JavaScript doesn't have abstract data structures like stacks and queues built into the language. Implementations of those structures use an array underneath. So so...
C++ Solution for Generate Parentheses Leetcode Problem #22
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example 1: Input: n = 3 Output: ["((()))","(()())","(())()","()(())","()()()"] Example 2:...
Find Minimum in Rotated Sorted Array
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the a...
Find the Peek Element in the Array
Peak element https://www.geeksforgeeks.org/problems/peak-elementhttps://leetcode.com/problems/find-peak-elementDifficulty: BasicAccuracy: 38.86%Submissions: 510K+Points: 1 Given an array arr[] where no t...
Merge K Sorted Lists
https://leetcode.com/problems/merge-k-sorted-lists You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-...