Tag Archives: LeetCode

LeetCode – Pascal’s Triangle – JavaScript Dev Feed

LeetCode – Pascal’s Triangle Problem statement Given an integer numRows, return the first numRows of Pascal’s triangle. In Pascal’s triangle, each number is the sum of the two numbers directly above it as shown: Problem statement taken from: https://leetcode.com/problems/pascals-triangle Example 1: Input: numRows = 5 Output: [ [1], [1, 1], [1, 2, 1], [1, 3,…

Read More

Leetcode 56: Merge Intervals – Python Dev Feed

Leetcode 56: Merge Intervals Problem statement:https://leetcode.com/problems/merge-intervals/ Straight forward solution is to sort the intervals by start time, iterate them and check if two intervals overlap. If they overlap we take the union of those intervals; Otherwise, we take both of them. Python class Solution: def merge(self, intervals: List[List[int]]) -> List[List[int]]: # sort intervals by start…

Read More

LeetCode 133. Clone Graph (javascript solution) – JavaScript Dev Feed

LeetCode 133. Clone Graph (javascript solution) Description: Given a reference of a node in a connected undirected graph. Return a deep copy (clone) of the graph. Each node in the graph contains a value (int) and a list (List[Node]) of its neighbors. class Node {public int val;public List neighbors;} Test case format: For simplicity, each…

Read More

LeetCode – Median of Two Sorted Arrays – JavaScript Dev Feed

LeetCode – Median of Two Sorted Arrays Problem statement Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Problem statement taken from: https://leetcode.com/problems/median-of-two-sorted-arrays Example 1: Input: nums1 = [1, 3], nums2 = [2] Output:…

Read More