Intersection of Two Linked Lists LeetCode Solution

Problem Statement Intersection of Two Linked Lists LeetCode Solution – We are given the heads of two strongly linked-lists headA and headB. It is also given that the two linked lists may intersect at some point. We are asked to return the node at which they intersect or null if …

Read more

Defanging an IP Address LeetCode Solution

Problem Statement Defanging an IP Address LeetCode Solution – Given a valid (IPv4) IP address, return a defanged version of that IP address. A defanged IP address replaces every period “.” with “[.]”. Input: address = “1.1.1.1” Output: “1[.]1[.]1[.]1” Explanation The intuition is very simple. 1. create a Stringbuilder str 2. loop through the address string …

Read more

Merge Sorted Array LeetCode Solution

Problem Statement Merge Sorted Array LeetCode Solution – You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. Merge nums1 and nums2 into a single array sorted in non-decreasing order. The final sorted array should not be returned by the function, but instead be stored inside the array nums1. …

Read more

Delete Node in a Linked List Leetcode Solution

Problem Statement : Delete Node in a Linked List Leetcode Solution – Write a function to delete a node in a singly-linked list. You will not be given access to the head of the list, instead, you will be given access to the node to be deleted directly. It is guaranteed that the node to be deleted is not …

Read more

Build Array From Permutation Leetcode Solution

Problem Statement The Build Array From Permutation LeetCode Solution – “Build Array From Permutation” states that given zero-based permutation nums, we have to build an array of the same length where ans[i] = nums[nums[i]] for each i in range [0,nums.length-1]. A zero-based permutation nums is an array of distinct integers from 0 …

Read more

Find if Path Exists in Graph Leetcode Solution

Problem Statement Find if Path Exists in Graph Leetcode Solution – There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n – 1 (inclusive). The edges in the graph are represented as a 2D integer array edges, where each edges[i] = [ui, vi] denotes a bi-directional edge between vertex ui and vertex vi. Every vertex pair …

Read more

Cells with Odd Values in a Matrix LeetCode Solution

Problem Statement Cells with Odd Values in a Matrix LeetCode Solution –  There is an m x n matrix that is initialized to all 0‘s. There is also a 2D array indices where each indices[i] = [ri, ci] represents a 0-indexed location to perform some increment operations on the matrix. For each location indices[i], we need to …

Read more

Sign of the Product of an Array LeetCode Solution

Problem Statement Sign of the Product of an Array LeetCode Solution – There is a function signFunc(x) that returns: 1 if x is positive. -1 if x is negative. 0 if x is equal to 0. You are given an integer array nums. Let product be the product of all values in the array nums. Return signFunc(product). Input: nums = [-1,-2,-3,-4,3,2,1] Output: 1 Explanation: The product …

Read more

Translate »