Posts

Showing posts from 2021

LeetCode Problem 1041- Robot Bounded In Circle - Level - Medium

Image
LeetCode 1041 - Robot Bounded In a Circle Today we are going to look at another LeetCode problem  1041 robot bounded in a circle with difficulty level medium. Problem Statement : From given problem statement , Robot can perform certain given sets of instruction either G,R,L and corresponding action can be taken. After performing instruction if robot come back to original position (0,0) that means robot will stay in circle and will never leave it. Let's understand more in details about behaviour of robot. Robot is standing at position (0,0) coordinates and facing North.  G >> Move One Step Ahead. That mens increment Y coordinate by One. R >> Rotate Robot to 90 degree right but stay there. L >> Rotate robot on left with 90.  Let's understand this problem by example given in problem statement. Command : GGLLGG Step 1 : First robot gets input at GG which means robot will move 2 step ahead by incrementing Y coordinates. So current position of robot will be (X,Y)

Leet Code Problem - 69 - Sqrt(x) - Difficulty Level : Easy

Image
 Hello All, Welcome back to another algorithm challenge. Today we are going to look at LeetCode problem number 69 where you need to find square root of input number. Please find below link for detailed statement of problem. https://leetcode.com/problems/sqrtx/ Now if we read that problem statement , it's given that we can not use  pow(x, 0.5)  or  x ** 0.5. Now instead of focusing on calculating power root , we will focus on calculating square of number and we try to compare with input weather it matches or not. If my input greater is less than power we calculated , then again we loop find bigger square value. Now one approach to solve this problem is you start with number 1 and keep calculating square until you reach either equal or greater number than input provided. But this approach will increase my time complexity. Better approach would to use Binary Search algorithm approach which can give me result in O(logn) time. Algorithm : Let's looks at step by step approach how wou

LeetCode Problem 66 - Plus One - Algorithm and Java Solution

 Hi Friends, Today we are going to solve a leetcode problem number 66. Please feel free to read problem description from below link. https://leetcode.com/problems/plus-one/ In given problem , it states that you have a non-empty and non-negative array storing single digit value at each position and most significant bit is stored at head of list. Now we look at below example , when 1 is added to last digit 3 , it becomes 4 which would be simple to achieve. Input: digits = [1,2,3] Output: [1,2,4] Explanation: The array represents the integer 123. But problem comes when last digit is 9 where you add 1 , it becomes 2 digit number = 10 which is not allowed in array. So in that you have keep 0 at unit place and use carry 1 to be added in next digit. For Example  Input: digits = [1,2,9] Output: [1,3,0] Explanation: The array represents the integer 130. Now in above example , 1 added to 9 is replaced with 0 and carry got added to 2 became 3. Corner Case: Everything works fine except where

Taints and Tolerations Example in Kubernetes

Image
Taints and Tolerations are advance scheduling mechanism designed to repel pods if they do not have matching toleration.  Pods are only accepted by Nodes if they match desired toleration otherwise Pods remains in Pending state or look for another nodes. In today's example , we will configure nodes and pods with taints and toleration respectively. We will make use of Minikube cluster for managing pods. Pre-requisite : Minikube Cluster  As you can see in above picture , we have two pod one with toleration defined and another without toleration. Since minikube is just one node cluster , we will use master node and apply taints on it. We will see pod scheduling behaviour when toleration applied versus toleration not applied. Let's make sure minikube cluster is running fine and check if master node has taints applied on it. kubectl describe nodes minikube | grep -i taints As you can currently no taints is applied on minikube master node , in this case any pod can be schedule