Prashant Mishra

Prashant Mishra @prashantrmishra

About: There is always a price for those who persevere.

Location:
India
Joined:
Jul 2, 2022

Prashant Mishra
articles - 197 total

Copy Linked List with random pointer

Problem tc :O(n) where n is no. of nodes in the original linked list Iterative approach: /* //...

Learn More 0 0Apr 18

Add 1 to the list

Problem tc :O(n), sc:O(1) /* class Node{ int data; Node next; Node(int x){ ...

Learn More 0 0Apr 6

Largest Divisible subset

Problem Backtracking solution (TLE) tc : O(2^n) class Solution { List<Integer> result ...

Learn More 0 0Apr 6

Daily Temperatures

Problem Same as : Next greater element than the stack top class Solution { public int[]...

Learn More 0 0Mar 22

Clone graph

O(n) : where n is no. of nodes Problem /* Definition for a Node. class Node { public int val; ...

Learn More 0 0Mar 20

3108. Minimum Cost Walk in Weighted Graph

Problem TC: O(n*4alpha) class Solution { public int[] minimumCost(int n, int[][] edges,...

Learn More 0 0Mar 20

Valid Binary Search Tree

Problem TC: O(n), SC: O(n) /** * Definition for a binary tree node. * public class TreeNode { ...

Learn More 0 0Mar 19

Minimum Time to repair cars

Problem TC: O(nlog(k)), where k is the max time in the range between 1 to r*n^2 class Solution { ...

Learn More 0 0Mar 16

House Robber IV

Problem TC: O(nlog(Max(nums))) class Solution { public int minCapability(int[] nums, int k)...

Learn More 0 0Mar 15

Maximum Candies Allocated to K Children

Problem //same as coco eating bananas, //capacity to ship packages within d days //aggresive...

Learn More 0 0Mar 14

Count of Substrings Containing Every Vowel and K Consonants II

Problem Pattern: number of subarray/substring with condition like sum ==k or count = k TC:...

Learn More 0 0Mar 10

Circular Sorting

Find missing number class Solution { public int missingNumber(int[] nums) { //circular...

Learn More 0 0Mar 3

Spiral matrix

Problem TC: O(n*m) class Solution { public List<Integer> spiralOrder(int[][] matrix) { ...

Learn More 0 0Feb 15

Design and search word

Problem class WordDictionary { Trie t; public WordDictionary() { t = new Trie(); ...

Learn More 0 0Feb 6

Grid Game

Problem TC: O(n) SC: O(n) class Solution { public long gridGame(int[][] grid) { long...

Learn More 0 0Jan 23

Sum of variable length subarray

Problem TC: O(n) SC:O(n) class Solution { public int subarraySum(int[] nums) { int...

Learn More 0 0Jan 20

Minimum obstacle removal to reach corner

TC:O(n*mlog(n*m)) SC :O(n*m) Problem //BFS : dijkstra's class Solution { public int...

Learn More 0 0Jan 18

Walls and Gates

Problem TC:O(n*m) SC:O(n*m) import java.util.* ; import java.io.*; class Pair<T> { T...

Learn More 0 0Jan 18

Safest walk through the grid

Problem TC : O(n*mlog(n*m)) SC: O(n*m) //BFS approach (dijkstra's algorithm) class Triple{ ...

Learn More 0 0Jan 18

1368. Minimum Cost to Make at Least One Valid Path in a Grid

Problem Same as Minimum Obstacle removal to reach corner Time Complexity: O(n*mlog(n*m) Space...

Learn More 0 0Jan 18

Count (*) between pipes (|)

Problem Statement: Count Stars Between Pipes Problem Description You are given...

Learn More 0 0Jan 18

Minimize XOR

Problem TC : (n+m) where n and m are no. of bits in num1 and num2 respectively /* use...

Learn More 0 0Jan 16

Count prefix and suffix I and II

Count prefix and suffix I Brute force approach: TC: O(n^2*m), n is words.length and m is the...

Learn More 0 0Jan 8

Rabin Karp (hashing) String pattern matching

Problem TC:O(n) and SC: O(n) // using rabin karp hashing approach class Solution { public...

Learn More 0 0Jan 7

Min no. of operations to move all balls to each box

Problem This is similar to Product of array except self TC: O(n) ,SC:O(n) # this is same as...

Learn More 0 0Jan 6

Find all anagrams in the string[Fixed Window pattern]

Problem TC:O(n) SC:(k) is no. of substrings(anagrams) + O(1) for using constant space array of size...

Learn More 0 0Jan 4

No of ways to split Array

Problem TC: O(n) for calculating prefix sum, and O(n) for iterating over the prefix sum for...

Learn More 0 0Jan 3

Range sum query 2D - Immutable

Problem TC: O(n*m) for creating the prefix[][] sum matrix, O(row1+row2) for calculating the sum of...

Learn More 0 0Jan 2

Count vowel strings in ranges

Problem TC: O(n) for calculating the prefix[] and O(k) for getting all the counts of the vowels in...

Learn More 0 0Jan 2

Range Sum Query - Immutable

Problem TC: O(n) for calculating the prefix sum and O(1) for getting the sum of the subarray in the...

Learn More 0 0Jan 2