
Aspiring Software Developer ⚫ Coding in C++ ⚫ Learning JS and Java
India
Joined October 2021
- Tweets38
- Following88
- Followers9
- Likes110
LeetCode Problem 50. Pow(x, n)
Implement pow(x, n), which calculates x raised to the power n (i.e., x^n).
Sol : O(logn) time & O(1) space (Binary Exponentiation)
#100DaysOfCode #programming #codingisfun #code #SoftwareEngineer #developers #problemsolving
1
1
LeetCode Problem 134: Gas Station
Given 2 arrays A & B, return starting index of circular path AB such that at no time summation(A[i]-B[i]) is negative
Sol : O(n) time & O(1) space
#100DaysOfCode #programming #codingisfun #code #SoftwareEngineer #developers #problemsolving
Problem : Count Inversions Type (2)
Link : leetcode.com/problems/global…
Check if local and global inversions are different .
Local Inversion : a[i]>a[i+1]
Sol : O(n) time & O(1) space
#100DaysOfCode #programming #codingisfun #code #SoftwareEngineer #developers #problemsolving
Problem : Count Inversions in Array
Two elements a[i] and a[j] form an inversion if a[i] > a[j] and i < j.
Sol : O(nlogn) time & O(n) space
#100DaysOfCode #programming #codingisfun #code #SoftwareEngineer #developers #problemsolving
Problem : Find Duplicate and Missing Number
Constant array of n integers, each is in the range [1, n] inclusive. 1 integer is repeated and 1 is missing
Sol : O(n) time & O(1) space
#100DaysOfCode #programming #codingisfun #code #SoftwareEngineer #developers #problemsolving
1
LeetCode Problem 287: Find Duplicate
Array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive.
Sol : O(n) time & O(1) space (C++/Java)
#100DaysOfCode #programming #codingisfun #code #SoftwareEngineer #developers #problemsolving
LeetCode Problem 88: Merge Sorted Array
Merge into 1 sorted array A1 .Extra space is given in A1 to hold both arrays
A1 = [1,2,3,0,0,0]
A2 = [2,5,6]
Sol : O(m+n) time & O(1) space
#100DaysOfCode #programming #codingisfun #code #SoftwareEngineer #developers #problemsolving
LeetCode Problem : Check Valid Matrix
An n x n matrix is valid if every row and every column contains all the integers from 1 to n (inclusive).
Sol : O(n^2) time & O(1) space
#100DaysOfCode #programming #codingisfun #code #SoftwareEngineer #developers #problemsolving
1
1
LeetCode Problem 56: Merge Intervals
Given an array of intervals where intervals[i] = [start-i, end-i], merge all overlapping intervals
Sol : O(nlogn) time & O(n) space
#100DaysOfCode #programming #codingisfun #code #SoftwareEngineer #developers #problemsolving
LeetCode Problem 48: Rotate Image
Given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise).
Sol : O(n^2) time & O(1) space
#100DaysOfCode #programming #codingisfun #code #SoftwareEngineer #developers #problemsolving
LeetCode Problem 121: Buy & Sell Stock
Prices[i] is the price of a given stock on the ith day. Maximize profit by choosing a day to buy & other day to sell
Sol : O(n) time & O(1) space
#100DaysOfCode #programming #codingisfun #code #SoftwareEngineer #developers #problemsolving

ALT We make 2 variables small and big which track smallest and biggest seen during traversal . We also track the largest profit we have seen in each iteration . If we find a smaller number we update both small and big because as previous value of big is now useless . If we find a bigger value we update big
LeetCode Problem 75: Sort Colors
Given an integer array of 0,1,2 , sort it in O(n) time
Solution : O(n) time and O(1) space
#100DaysOfCode #programming #Coding #code #softwareengineer #Developers #ProblemSolving
LeetCode Problem 53. Maximum Subarray (Kadane's Algorithm)
Given an integer array , find the contiguous subarray with largest sum
Solution : O(n) time and O(1) space
#100DaysOfCode #programming #Coding #code #softwareengineer #Developers #problemsolving
LeetCode Problem 31: Next Permutation
Find next permutation of given sequence
Solution : O(n) time and O(1) space
#100DaysOfCode #programming #Coding #code #softwareengineer #javascript #Developers #problemsolving #CProgramming
LeetCode Problem 118: Pascal's Triangle
Find Pascal's triangle with n rows
Solution : O(n^2) time and space
#100DaysOfCode #programming #Coding #SoftwareEngineer
LeetCode Problem 73: Set Matrinx Zeroes
Set i row and j col 0 if matrix[i][j]=0
Solution1 : O(mn) time and O(m+n) space
Efficient : O(mn) time and O(1) space
#100DaysOfCode #programming #Coding #SoftwareEngineer
LeetCode Problem 231 : Power Of Two
Find if n , an integer , is power of 2 . An integer is power of 2 if we can write n=2^x
Recursion : O(log(n)) time and space
Using Logarithms : O(log(n)) time and O(1) space
#100DaysOfCode #programming #Coding #SoftwareEngineer
LeetCode Problem 198 : House Robber
Given an array of numbers , find max sum such that no 2 numbers are consecutive
Memoization : O(n) time and space
#100DaysOfCode #programming #Coding #SoftwareEngineer





















