Tag

cracking the coding interview

44 posts

Leetcode Solution - Best Time to Buy and Sell Stock

Leetcode Solution - Best Time to Buy and Sell Stock

Problem Statement You are given an array prices where prices[i] is the price of…

Binary Tree - Level Order Traversal

Binary Tree - Level Order Traversal

Problem Statement Given a Binary tree, print out nodes in level order traversal…

Four Sum - Leet Code Solution

Four Sum - Leet Code Solution

Problem Statement Given an array nums of n integers and an integer target, are…

Leetcode - Rearrange Spaces Between Words

Leetcode - Rearrange Spaces Between Words

Problem Statement You are given a string text of words that are placed among…

Leetcode - Maximum Non Negative Product in a Matrix

Leetcode - Maximum Non Negative Product in a Matrix

Problem Statement You are given a rows x cols matrix grid. Initially, you are…

Leetcode - Split a String Into the Max Number of Unique Substrings

Leetcode - Split a String Into the Max Number of Unique Substrings

Problem Statement Given a string s, return the maximum number of unique…

Crawler Log Folder - minimum number of operations needed to go back to the main folder after the change folder operations.

Crawler Log Folder - minimum number of operations needed to go back to the main folder after the change folder operations.

Problem The Leetcode file system keeps a log each time some user performs a…

Replace all spaces in a string with %20

Replace all spaces in a string with %20

Problem Statement Replace all spaces in a string with ‘%20’ (three characters…

Determine if a string has all unique characters

Determine if a string has all unique characters

Problem Implement an algorithm to determine if a string has all the characters…

Valid Palindrome - Leet Code Solution

Valid Palindrome - Leet Code Solution

Problem Statement Given a string, determine if it is a palindrome, considering…

Valid Anagrams - Leet Code Solution

Valid Anagrams - Leet Code Solution

Problem Statement Given two strings s and t , write a function to determine if t…

First Unique Character in a String - Leet Code Solution

First Unique Character in a String - Leet Code Solution

Problem Statement Given a string, find the first non-repeating character in it…

Reverse String - Leet Code Solution

Reverse String - Leet Code Solution

Problem Statement Write a function that reverses a string. The input string is…

Rotate Image - Leet Code Solution

Rotate Image - Leet Code Solution

Problem Statement You are given an n x n 2D matrix representing an image, rotate…

Validate Sudoku - Leet Code Solution

Validate Sudoku - Leet Code Solution

Problem Statement Determine if a 9x9 Sudoku board is valid. Only the filled…

Plus One - Leet Code Solution

Plus One - Leet Code Solution

Problem Statement Given a non-empty array of digits representing a non-negative…

Move Zeroes - Leet Code Solution

Move Zeroes - Leet Code Solution

Problem Statement Given an array nums, write a function to move all 0’s to the…

Intersection of Two Arrays-II - Leet Code Solution

Intersection of Two Arrays-II - Leet Code Solution

Problem Statement Given two arrays, write a function to compute their…

Find if Array contains Duplicate Number - Leet Code Solution

Find if Array contains Duplicate Number - Leet Code Solution

Problem Statement Given an array of integers, find if the array contains any…

Single Number - Leet Code Solution

Single Number - Leet Code Solution

Problem Statement Given a non-empty array of integers, every element appears…

Maximum Length of Subarray With Positive Product - Leet Code Solution

Maximum Length of Subarray With Positive Product - Leet Code Solution

Problem Statement Maximum Length of Subarray With Positive Product. Given an…

Rotate Array - Leet Code Solution

Rotate Array - Leet Code Solution

Problem Statement Given an array, rotate the array to the right by k steps…

Calculate Max Profit - Buy and Sell Stocks Multiple Times - Leet Code Solution

Calculate Max Profit - Buy and Sell Stocks Multiple Times - Leet Code Solution

Problem Statement Say you have an array prices for which the ith element is the…

Remove Duplicates from Sorted Array - Leet Code Solution

Remove Duplicates from Sorted Array - Leet Code Solution

Problem Statement Given a sorted array nums, remove the duplicates in-place such…

How to calculate First Common Ancestor of two Nodes in Binary Tree

How to calculate First Common Ancestor of two Nodes in Binary Tree

First try to understand question. Its a binary tree, not a binary search tree…

Swap Nodes Pairs in Link List - Leet Code Solution

Swap Nodes Pairs in Link List - Leet Code Solution

Problem Statement Given a linked list, swap every two adjacent nodes and return…

Three Sum - Leet Code Solution

Three Sum - Leet Code Solution

Problem Statement Given an array nums of n integers, are there elements a, b, c…

Three Sum Closest - Leet Code Solution

Three Sum Closest - Leet Code Solution

Problem Statement Given an array nums of n integers and an integer target, find…

Convert Roman to Integer number - Leet Code Solution

Convert Roman to Integer number - Leet Code Solution

Problem Statement Roman numerals are represented by seven different symbols: I…

Integer to Roman conversion - Leet Code Solution

Integer to Roman conversion - Leet Code Solution

Problem Statement Roman numerals are represented by seven different symbols: I…

Longest Common Prefix - Leet Code Solution

Longest Common Prefix - Leet Code Solution

Problem Statement Write a function to find the longest common prefix string…

Container with Most Water - Leet Code Solution

Container with Most Water - Leet Code Solution

Problem Statement Given n non-negative integers a1, a2, …, an , where each…

Check whether an integer number given is palindrome or not - Leet Code Solution

Check whether an integer number given is palindrome or not - Leet Code Solution

Problem Statement Determine whether an integer is a palindrome. An integer is a…

Remove nth Node from Last - Leet Code Solution

Remove nth Node from Last - Leet Code Solution

Problem Statement Given a linked list, remove the n-th node from the end of list…

How to calculate angle between hour and minute hand, given a time

How to calculate angle between hour and minute hand, given a time

This problem is a simple mathematical calculation. Lets start deriving some…

Convert String to Integer - atoi - Leet Code Solution

Convert String to Integer - atoi - Leet Code Solution

Problem Statement Implement atoi which converts a string to an integer…

Check whether number is palindrome or not - Leet Code Solution

Check whether number is palindrome or not - Leet Code Solution

Problem Statement Determine whether an integer is a palindrome. An integer is a…

Zigzag Pattern String Conversion - Leet Code Solution

Zigzag Pattern String Conversion - Leet Code Solution

Problem Statement The string “PAYPALISHIRING” is written in a zigzag pattern on…

Reverse digits of a signed integer - Leet Code Solution

Reverse digits of a signed integer - Leet Code Solution

Problem Statement Given a signed integer, reverse digits of an integer. Return…

Longest Palindrome Substring - Leet Code Solution

Longest Palindrome Substring - Leet Code Solution

Problem Statement Given a string s, find the longest palindromic substring in s…

Find the Median of Two Sorted Arrays - Leet Code Solution

Find the Median of Two Sorted Arrays - Leet Code Solution

Problem Statement There are two sorted arrays nums1 and nums2 of size m and n…

Longest Substring without repeating characters - Leet Code Solution

Longest Substring without repeating characters - Leet Code Solution

Problem Statement Given a string, find the length of the longest substring…

Add two numbers(reverse order) link list Problem - Leet Code Solution

Add two numbers(reverse order) link list Problem - Leet Code Solution

Problem Statement You are given two non-empty linked lists representing two non…

Two Sum Problem - Leet Code Solution

Two Sum Problem - Leet Code Solution

Problem Statement Given an array of integers, return indices of the two numbers…