Category: fullstackdevelopment
-
Data Structures & Algorithms in Java – Dynamic Programming- Minimum Coin Change
Problem: Given a set of coins and an amount , find the minimum set of coins required to compute that amount. For example , If you are given the set of coins 1,2 and 5 ,you need to compute the number of coins required to calculate the amount of 11 rupees. Input: Coins = [1,2,5]…
-
Data Structures & Algorithms in Java – Binary – Reverse Bits
Problem: Given a number , reverse the bits in that number Input: 00000010100101000001111010011100 Output: 00111001011110000010100101000000 Since in Java the above binary number will be represented as an integer , the output should be 964176192 which is the decimal equivalent of the above binary number Assumptions: The input is stored in 32 bits (which is the…
-
Data Structures and Algorithms in Java – Arrays – Search in Rotated Sorted Array
Problem: Given an array of integers which is sorted and rotated , find out if the given element is in the array or not. A rotated array is an array whose elements are shifted towards the beginning from the end. For example , consider the array: input = [1,2,3,4,5] If this array is rotated once…
-
Data Structures and Algorithms in Java – Arrays – Product of Array Except Self – faster than 100% of submissions on leetcode!
Problem: Given an array of integers , find an array of products where each product is the product of all the numbers except the element in that index. ie) For every number number[i] , find the product of all the numbers except number[i] Input: numbers = [1,2,3,4] Output: [24,12,8,6] Calculated as below: 24 = 2*3*4…
-
Data Structures and Algorithms in Java – Arrays – Best time to buy and sell stock
Problem: You are given an array of stock prices with each index of the array representing each day. You need to buy stock one one day and sell it on another subsequent day. What is the maximum profit you can earn? Input: An integer array of prices: prices = [7,1,5,2,6,9] prices[i] denotes the price on…
-
Data Structures & Algorithms in Java – Arrays – Two sum
Problem: Given an array of integers and a sum , find two numbers in the array which match that sum and return their indices. Example: Input: [2, 6, 3, 9] – array of integers 8 – sum Output: 2 + 6 = 8 , index of 2 is 0 index of 6 is 1 So…
-
How to consume a data stream in javascript?
Dealing with huge amount of continuous data (data streams) is a challenge for enterprise applications. Fortunately , reactive programming provides a standard solution to this problem. You can generate and consume data streams without blocking the user and without overwhelming the server or client. This post explains how to do reactive programming on the server…
-
How to implement Reactive Programming in Spring Boot?
Programming comes in different paradigms. For long , we did procedural programming using languages like C where the business logic was executed step by step in a procedural manner. Then came Object Oriented Programming where you modeled your business requirement into domain objects. It represented real world more closely and has been quite successful even…
-
How to implement Transactional Outbox design pattern in Spring Boot Microservices?
Let’s say you have created a microservice. One of the APIs in the microservice does two operations: How can you make sure both are transactional? In other words if database update fails don’t send the message to the other service and if message sending fails rollback the database update? In Spring you handle transactions using…