Posts

Get Maximum in Generated Array

  You are given an integer   n . An array   nums   of length   n + 1   is generated in the following way: nums[0] = 0 nums[1] = 1 nums[2 * i] = nums[i]  when  2 <= 2 * i <= n nums[2 * i + 1] = nums[i] + nums[i + 1]  when  2 <= 2 * i + 1 <= n Return   the  maximum  integer in the array  nums ​​​. Example 1: Input: n = 7 Output: 3 Explanation: According to the given rules: nums[0] = 0 nums[1] = 1 nums[(1 * 2) = 2] = nums[1] = 1 nums[(1 * 2) + 1 = 3] = nums[1] + nums[2] = 1 + 1 = 2 nums[(2 * 2) = 4] = nums[2] = 1 nums[(2 * 2) + 1 = 5] = nums[2] + nums[3] = 1 + 2 = 3 nums[(3 * 2) = 6] = nums[3] = 2 nums[(3 * 2) + 1 = 7] = nums[3] + nums[4] = 2 + 1 = 3 Hence, nums = [0,1,1,2,1,3,2,3], and the maximum is 3. Example 2: Input: n = 2 Output: 1 Explanation: According to the given rules, the maximum between nums[0], nums[1], and nums[2] is 1. Example 3: Input: n = 3 Output: 2 Explanation:

Merge Sorted Array

Given two sorted integer arrays  nums1  and  nums2 , merge  nums2  into  nums1  as one sorted array. The number of elements initialized in  nums1  and  nums2  are  m  and  n  respectively. You may assume that  nums1  has enough space (size that is equal to  m + n ) to hold additional elements from  nums2 . Example 1: Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3 Output: [1,2,2,3,5,6] Example 2: Input: nums1 = [1], m = 1, nums2 = [], n = 0 Output: [1] Constraints: 0 <= n, m <= 200 1 <= n + m <= 200 nums1.length == m + n nums2.length == n -10 9  <= nums1[i], nums2[i] <= 10 9 Solution : class Solution {     public void merge(int[] nums1, int m, int[] nums2, int n) {         int i;         for(i=0;i<n;i++){             nums1[m+i] = nums2[i];         }         Arrays.sort(nums1);     } } Try it

Check If Two String Arrays are Equivalent

Given two string arrays  word1  and  word2 , return   true  if the two arrays  represent  the same string, and  false  otherwise. A string is  represented  by an array if the array elements concatenated  in order  forms the string. Example 1: Input: word1 = ["ab", "c"], word2 = ["a", "bc"] Output: true Explanation: word1 represents string "ab" + "c" -> "abc" word2 represents string "a" + "bc" -> "abc" The strings are the same, so return true. Example 2: Input: word1 = ["a", "cb"], word2 = ["ab", "c"] Output: false Example 3: Input: word1 = ["abc", "d", "defg"], word2 = ["abcddefg"] Output: true   Constraints: 1 <= word1.length, word2.length <= 10 3 1 <= word1[i].length, word2[i].length <= 10 3 1 <= sum(word1[i].leng

Merge Two Sorted Lists

Image
Merge two sorted linked lists and return it as a  sorted  list. The list should be made by splicing together the nodes of the first two lists. Example 1: Input: l1 = [1,2,4], l2 = [1,3,4] Output: [1,1,2,3,4,4] Example 2: Input: l1 = [], l2 = [] Output: [] Example 3: Input: l1 = [], l2 = [0] Output: [0] Constraints: The number of nodes in both lists is in the range  [0, 50] . -100 <= Node.val <= 100 Both  l1  and  l2  are sorted in  non-decreasing  order. Solution: /**  * Definition for singly-linked list.  * public class ListNode {  *     int val;  *     ListNode next;  *     ListNode() {}  *     ListNode(int val) { this.val = val; }  *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }  * }  */ class Solution {     public ListNode mergeTwoLists(ListNode l1, ListNode l2) {         ListNode temp = new ListNode();        

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,