Posts

132 Pattern

  Given an array of   n   integers   nums , a   132 pattern   is a subsequence of three integers   nums[i] ,   nums[j]   and   nums[k]   such that   i < j < k   and   nums[i] < nums[k] < nums[j] . Return  true  if there is a  132 pattern  in  nums , otherwise, return  false . Follow up:  The  O(n^2)  is trivial, could you come up with the  O(n logn)  or the  O(n)  solution?   Example 1: Input: nums = [1,2,3,4] Output: false Explanation: There is no 132 pattern in the sequence. Example 2: Input: nums = [3,1,4,2] Output: true Explanation: There is a 132 pattern in the sequence: [1, 4, 2]. Example 3: Input: nums = [-1,3,2,0] Output: true Explanation: There are three 132 patterns in the sequence: [-1, 3, 2], [-1, 3, 0] and [-1, 2, 0].   Constraints: n == nums.length ...

Ascending Star Pattern

Java Program to print * pattern as follows., INPUT n=5 OUTPUT * ** *** **** ***** CODE import java.util.*; public class Main { public static void main(String[] args) { int i, j, n; System.out.println("Enter the size of n:"); Scanner scan = new Scanner(System.in); n = scan.nextInt(); for(i=1;i<=5;i++){     for(j=1;j<=i;j++){         System.out.print("*");     }     System.out.println();  //Printing Next Line } System.out.println("\n==>>> https://thefellowprogrammer.blogspot.com/ <<<<<=="); } } Here, we are going to solve using two for loops. 1) Get input value of n 2) Outer for loop (i) acts as as variable which controls number of rows to be printed with help of inner loop.  (Eg) If i=2, only two '*' will be printed 3) Inner for loop (j) acts as a variable which number of columns (i.e., *) to be printe...

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++) {      ...

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]^num...