Posts

Showing posts from December, 2020

Determine if String Halves Are Alike

You are given a string   s   of even length. Split this string into two halves of equal lengths, and let   a   be the first half and   b   be the second half. Two strings are  alike  if they have the same number of vowels ( 'a' ,  'e' ,  'i' ,  'o' ,  'u' ,  'A' ,  'E' ,  'I' ,  'O' ,  'U' ). Notice that  s  contains uppercase and lowercase letters. Return  true  if  a  and  b  are  alike . Otherwise, return  false . Example 1: Input: s = "book" Output: true Explanation:  a = "b o " and b = " o k". a has 1 vowel and b has 1 vowel. Therefore, they are alike. Example 2: Input: s = "textbook" Output: false Explanation:  a = "t e xt" and b = "b oo k". a has 1 vowel whereas b has 2. Therefore, they are not alike. Notice that the vowel o is counted twice. Example 3: Input: s = "MerryChristmas" Output: false ...

Agile Principles

Image
In the previous article, we learned about Agile Manifesto . Here, in this article we are going to note down the principles of agile . Source: Google Principles of Agile: Satisfy Customer through early and continuous delivery. Welcome, change requirement even in late development. Deliver working software frequently [ i.e., couple of weeks to couple of months ] Business people and developers work together daily. Build projects under motivated individuals.[ Give each individual, a required environment, support they need and trust them to get the job done ] Convey information to developer team through face to face conversation. Working software is a primary progress. Promote sustainable development. Developer and Customer should develop constant pace indefinitely. Continuous attention for technical enhances and good design. Simplicity - art of maximising amount of not work done is essential. Best architectures, requirement, design, emerging from self organizing teams. At regular intervals,...

Balanced Binary Tree

Image
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as: a binary tree in which the left and right subtrees of  every  node differ in height by no more than 1. Example 1: Input: root = [3,9,20,null,null,15,7] Output: true Example 2: Input: root = [1,2,2,3,3,null,null,4,4] Output: false Example 3: Input: root = [] Output: true   Constraints: The number of nodes in the tree is in the range  [0, 5000] . -10 4  <= Node.val <= 10 4 Solution: /**  * Definition for a binary tree node.  * public class TreeNode {  *     int val;  *     TreeNode left;  *     TreeNode right;  *     TreeNode() {}  *     TreeNode(int val) { this.val = val; }  *     TreeNode(int ...

Smallest Range II

Given an array   A   of integers, for each integer   A[i]   we need to choose   either  x = -K  or  x = K , and add   x   to   A[i]  (only once) . After this process, we have some array  B . Return the smallest possible difference between the maximum value of  B  and the minimum value of  B . Example 1: Input: A = [1] , K = 0 Output: 0 Explanation : B = [1] Example 2: Input: A = [0,10] , K = 2 Output: 6 Explanation : B = [2,8] Example 3: Input: A = [1,3,6] , K = 3 Output: 3 Explanation : B = [4,6,3] Note: 1 <= A.length <= 10000 0 <= A[i] <= 10000 0 <= K <= 10000 Solution: class Solution {     public int smallestRangeII(int[] A, int K) { ...

Agile Manifesto

Image
In the previous article, we learned about history of Agile . Now, in this article you will find about the Manifesto of Agile  Source: Google Agile Manifesto: Below are the manifesto of Agile., Individuals and Interactions over process and tools Working software over comprehensive documentation Customer Collaboration over contract negotiation Responding to the change over following the plan. Also read: Principles of Agile Related Posts: List of all Leetcode Problems with Solutions and Explanation  Explore more on our blog Agile Contents Like us? Please do share with your friends ..!! Follow us to receive updates instantly. If you have any feedback/suggestions, leave it in a comment section which will be helpful for us to improve.

Agile History

Image
In this chapter, we are going to learn about Agile. Here, we discussed about few points which we will give you a history and evolution of agile. In whole learning most of the articles are written as points or notes, so that anyone can understand and learn easily. Source: Google Agile can be described in many ways. One among those is, Agile is not a specific model/process, it is a mindset. During early 1990's many of the light weight development models evolved to overcome drawbacks from Waterfall Model, Iterative Model etc. These includes Rapid Application Development (RAD), Unified process etc. After few years, around 2001, seventeen software developers together met at resort in Snowbird , Utah to discuss about Lightweight development model . These developers includes: Kent Beck, Dave Thomas, Ward Cunningham, Jeff Sutherland, Steve Mellor, Jon Kern, Brian Marick, Ken Schwaber, Jim Highsmith, Ron Jeffries, Andrew Hunt, James Grenning, Martin Fowler, Arie van Bennekum, Mike Beedle, R...

Validate Binary Search Tree

Image
Given the   root   of a binary tree,   determine if it is a valid binary search tree (BST) . A  valid BST  is defined as follows: The left subtree of a node contains only nodes with keys  less than  the node's key. The right subtree of a node contains only nodes with keys  greater than  the node's key. Both the left and right subtrees must also be binary search trees. Example 1: Input: root = [2,1,3] Output: true Example 2: Input: root = [5,1,4,null,null,3,6] Output: false Explanation: The root node's value is 5 but its right child's value is 4.   Constraints: The number of nodes in the tree is in the range  [1, 10 4 ] . -2 31  <= Node.val <= 2 31  - 1 Solution: /**  * Definition for a binary tree node.  * public class TreeNode {  *     int val;  *     TreeNode...

Squares of a Sorted Array

Given an integer array  nums  sorted in  non-decreasing  order, return  an array of  the squares of each number  sorted in non-decreasing order . Example 1: Input: nums = [-4,-1,0,3,10] Output: [0,1,9,16,100] Explanation: After squaring, the array becomes [16,1,0,9,100]. After sorting, it becomes [0,1,9,16,100]. Example 2: Input: nums = [-7,-3,2,3,11] Output: [4,9,9,49,121] Constraints: 1 <= nums.length <=  10 4 -10 4  <= nums[i] <= 10 4 nums  is sorted in  non-decreasing  order. Solution: class Solution {     public int[] sortedSquares(int[] nums) {                  for(int i=0;i<nums.length;i++){             nums[i] = nums[i] * nums[i];         }                ...

Smallest Subtree with all the Deepest Nodes

Given the   root   of a binary tree, the depth of each node is   the shortest distance to the root . Return  the smallest subtree  such that it contains  all the deepest nodes  in the original tree. A node is called  the deepest  if it has the largest depth possible among any node in the entire tree. The  subtree  of a node is tree consisting of that node, plus the set of all descendants of that node. Example 1: Input: root = [3,5,1,6,2,0,8,null,null,7,4] Output: [2,7,4] Example 2: Input: root = [1] Output: [1] Explanation: The root is the deepest node in the tree. Example 3: Input: root = [0,1,3,null,2] Output: [2] Explanation: The deepest node in the tree is 2, the valid subtrees are the subtrees of nodes 2, 1 and 0 but the subtree of node 2 is the smallest.   Constraints: The number of nodes in the tree will be in the range  [1, 500] . 0...

Valid Mountain Array

Given an array of integers  arr , return   true  if and only if it is a valid mountain array . Recall that arr is a mountain array if and only if: arr.length >= 3 There exists some  i  with  0 < i < arr.length - 1  such that: arr[0] < arr[1] < ... < arr[i - 1] < A[i] arr[i] > arr[i + 1] > ... > arr[arr.length - 1]   Example 1: Input: arr = [2,1] Output: false Example 2: Input: arr = [3,5,5] Output: false Example 3: Input: arr = [0,3,2,1] Output: true   Constraints: 1 <= arr.length <= 10 4 0 <= arr[i] <= 10 4 Solution: class Solution {     public boolean validMountainArray(int[] arr) {         int n = arr.length, i = 0, j = n - 1;         while (i+1  < n &...