Posts

Showing posts from 2021

SubArraySum

Image
Solving problem with javascript really fun. Lets build the basic build blocks. Problem: In an array of integers find the number of combinations of subarray for an expected target. Take a use case in real life, you have $50 in hand. You can pick items next to each other in an aisle. Find how many possibilities. Price of each item given as follows. [10, 12,  38,  20, 10, 5, 15] How do we pick in real life? We can pick items [12, 38] or [20, 10, 5, 15] which are continues.  It is easy for us when such a small data provided. Imaging 1000 continues array like below:  [ 8,  43, 24, 98, 39, 48, 96, 16, 60, 61, 74, 52, 82, 45, 37, 4, 69, 26, 40, 5, 5, 4, 51, 78, 47, 94, 89, 35, 33, 28, 2, 97, 69, 74, 57, 45, 90, 64, 36, 23, 88, 96, 63, 100, 86, 33, 4, 29, 18, 2, 21, 11, 6, 100, 82, 33, 10, 92, 23, 47, 95, 56, 37, 98, 3, 64, 40, 22, 97, 92, 79, 40, 12, 70, 43, 4, 93, 71, 96, 57, 22, 18, 93, 67, 41, 56, 89, 98, 6, 91, 43, 89, 87, 2, 65, 10, 44, 31, 31, 80, 69, 83, 66, 26,...

LinkedList - React Show

Image
  LinkedList implementation using Array Structure -- React   LinkedList implementation and invoke it through React Node definition LinkedList implementation Lets add methods to it Not enough, Lets show the behavior in UI  

Recursion

Image
 Recursion, tail optimization and memoization are important piece of Functional programming. Before jumping into solving complex solutions, I slip on basic structure of recursion lot of times. What is base case and what is recursive step? When I ask most recursive person at home, got the answer as "until I need a charge". Seriously??? I don't know what algorithm it is!!???. It moves all around without any pattern until completely got drained. ☺ May be it is the algorithm... So finding the base case says when to stop.   Another programming example: We are given a denomination of coins/ currency notes and amount of value. We need to identify the minimum number of coins/ currency notes required for calculating that amount. For the amount $3.15, we need to pick up 12 quarters, 1 dime and 1 nickel. So total number of coins is 14 coins. The base case here -> if total of value is equal to the amount required. The recursive step -> pick a higher denomination available to re...