Posts

Showing posts from September, 2020

Sequential Digits

An integer has sequential digits if and only if each digit in the number is one more than the previous digit. Return a sorted list of all the integers in the range [low, high]  inclusive that have sequential digits. Example 1: Input: low = 100, high = 300 Output: [123,234] Example 2: Input: low = 1000, high = 13000 Output: [1234,2345,3456,4567,5678,6789,12345] Constraints: 10 <= low <= high <= 10^9 class Solution {     public List<Integer> sequentialDigits(int low, int high) {         List<Integer> result = new ArrayList();         String str = "123456789";         int i, j, length = str.length(), num;         for( i = 2; i <= length; i++) {             for( j = 0; j <= length - i; j++) {                  num = Integer.parseInt(str.substring(j, j + i));                 if(num > high) return result;                 if(num >= low) result.add(num);             }         }                  return result;     } } Try it on Le

Paytm App removed from PlayStore in India?

Image
  Paytm has mysteriously disappeared from Google Play Store. The app, owned by One97 Communications Ltd, is not visible on being searched on Google Play Store whereas all the other apps including Paytm For Business, Paytm Money, Paytm Mall, and others owned by the company are still available on Play Store. Source: Google Commenting on the removal from Play Store, Paytm in a statement on Twitter said, "Paytm Android app is temporarily unavailable on Google's Play Store for new downloads or updates. It will be back very soon. All your money is completely safe, and you can continue to enjoy your Paytm app as normal." Google has apparently removed the Paytm app because it allegedly violates the company’s new rules around online gambling. A source within Google said that the Google team that worked with developers reached out to Paytm repeatedly to fix the issues with the app. However, Paytm made repeated violations of the Google policy, noted the source. Paytm vanished from G

Robot Bounded In Circle

On an infinite plane, a robot initially stands at (0, 0) and faces north.  The robot can receive one of three instructions: "G" : go straight 1 unit; "L" : turn 90 degrees to the left; "R" : turn 90 degress to the right. The robot performs the instructions given in order, and repeats them forever. Return true if and only if there exists a circle in the plane such that the robot never leaves the circle. Example 1: Input: "GGLLGG" Output: true Explanation: The robot moves from (0,0) to (0,2), turns 180 degrees, and then returns to (0,0). When repeating these instructions, the robot remains in the circle of  radius 2 centered at the origin. Example 2: Input: "GG" Output: false Explanation: The robot moves north indefinitely. Example 3: Input: "GL" Output: true Explanation: The robot moves from (0, 0) -> (0, 1) -> (-1, 1) -> (-1, 0) -> (0, 0) -> ... Note: 1 <= instructions.length <=

Maximum XOR of Two Numbers in an Array

  Given a   non-empty   array of numbers, a 0 , a 1 , a 2 , … , a n-1 , where 0 ≤ a i   < 2 31 . Find the maximum result of a i  XOR a j , where 0 ≤  i ,  j  <  n . Example: Input: [3, 10, 5, 25, 2, 8] Output: 28 Explanation: The maximum result is 5 ^ 25 = 28.   class Solution {     public int findMaximumXOR(int[] nums) {         int i, j, length = nums.length, max=0;         for(i=0;i<length;i++){             int tmp = 0;             for(j=0;j<length;j++){                 if(i!=j){                     tmp = nums[i]^nums[j];                     if(tmp > max){                         max = tmp;                     }                 }          

Word Pattern

Given a pattern and a string s , find if s  follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in s . Example 1: Input: pattern = "abba", s = "dog cat cat dog" Output: true Example 2: Input: pattern = "abba", s = "dog cat cat fish" Output: false Example 3: Input: pattern = "aaaa", s = "dog cat cat dog" Output: false Example 4: Input: pattern = "abba", s = "dog dog dog dog" Output: false   Constraints: 1 <= pattern.length <= 300 pattern contains only lower-case English letters. 1 <= s.length <= 3000 s contains only lower-case English letters and spaces ' ' . s does not contain any leading or trailing spaces. All the words in s are separated by a single space .   class Solution {     public boolean wordPattern(String pattern, String s) {         H