Skip to main content

Posts

Showing posts from 2022

Pattern 1 | aCoding | Day 1

Problem:   1. You are given a number n. 2. You've to create a pattern of * and separated by tab as shown in output format. Input Format A number n Constraints 1 <= n <= 100 Sample Input 2 Sample Output * * * Solution: import java.util.*; public class Main { public static void main(String[] args) { Scanner scn = new Scanner(System.in); // write ur code here int n = scn.nextInt(); for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++) System.out.print("*\t"); System.out.println(); } } } Follow us for more such content...

Flood Fill

 1. You are given a number n, representing the number of rows. 2. You are given a number m, representing the number of columns. 3. You are given n*m numbers, representing elements of 2d array a. The numbers can be 1 or 0 only. 4. You are standing in the top-left corner and have to reach the bottom-right corner.  Only four moves are allowed 't' (1-step up), 'l' (1-step left), 'd' (1-step down) 'r' (1-step right). You can only move to cells which have 0 value in them. You can't move out of the boundaries or in the cells which have value 1 in them (1 means obstacle) 5. Complete the body of floodfill function - without changing signature - to print all paths that can be used to move from top-left to bottom-right. Note1 -> Please check the sample input and output for details Note2 -> If all four moves are available make moves in the order 't', 'l', 'd' and 'r' Input Format A number n A number m e11 e12.. e21 e22.. ..

Print Maze Paths

1. You are given a number n and a number m representing number of rows and columns in a maze. 2. You are standing in the top-left corner and have to reach the bottom-right corner. Only two moves are allowed 'h' (1-step horizontal) and 'v' (1-step vertical). 3. Complete the body of pri tMazePath function - without changing signature - to print the list of all paths that can be used to move from top-left to bottom-right. Use sample input and output to take idea about output. Input Format A number n A number m Output Format Print paths (one path in each line) in order hinted by Sample output Constraints 0 <= n <= 10 0 <= m <= 10 Sample Input 2 2 Sample Output hv vh Solution: import java.io.*; import java.util.*; public class Main {     public static void main(String[] args) throws Exception {             Scanner sc = new Scanner(System.in);             int n = sc.nextInt(), m = sc.nextInt();             printMazePaths(1,1,n,m,"");     }    

Balanced Brackets

1. You are given a string exp representing an expression. 2. You are required to check if the expression is balanced i.e. closing brackets and opening brackets match up well. e.g. [(a + b) + {(c + d) * (e / f)}] -> true [(a + b) + {(c + d) * (e / f)]} -> false [(a + b) + {(c + d) * (e / f)} -> false ([(a + b) + {(c + d) * (e / f)}] -> false Input Format A string str Output Format true or false Constraints 0 <= str.length <= 100 Sample Input [(a + b) + {(c + d) * (e / f)}] Sample Output true Solution import java.io.*; import java.util.*; public class Main {     public static void main(String[] args) throws Exception {         Scanner sc = new Scanner(System.in);         String str = sc.nextLine();         int n = str.length();         Stack<Character> s = new Stack<>();         for(int i=0;i<n;i++){             char ch = str.charAt(i);             if(ch == '[')                 s.push(']');             else if(ch == '{'

Lucky Number | SnackDown 2021 - Online Qualifiers

Given three digits  A A ,  B B , and  C C  of the lottery ticket, tell whether Chef wins something or not? Input Format First line will contain  T T , the number of test cases. Then the test cases follow. Each test case contains a single line of input, three space separated integers  A , B , C A , B , C . Output Format For each testcase, output in a single line answer  "YES"  if Chef wins a positive amount with the lottery and  "NO"  if not. You may print each character of the string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). Constraints 1 ≤ T ≤ 1000 1 ≤ T ≤ 1000 0 ≤ A , B , C ≤ 9 0 ≤ A , B , C ≤ 9 Sample Input 1  3 0 0 0 7 8 9 2 7 7 Sample Output 1  NO YES YES Explanation Test Case  1 1 :  Since no digit is equal to  7 7 , Chef fails to win any amount in the lottery. Test Case  2 2 :  Since the first digit is equal to  7 7 , Chef will win some amount

Tiling With M * 1 Tiles

 1. You are given a number n and a number m separated by line-break representing the length and breadth of a m * n floor. 2. You've an infinite supply of m * 1 tiles. 3. You are required to calculate and print the number of ways floor can be tiled using tiles. Input Format A number n A number m Output Format A number representing the number of ways in which the number of ways floor can be tiled using tiles. Constraints 1 <= n <= 100 1 <= m <= 50 Sample Input 39 16 Sample Output Solution import java.io.*; import java.util.*; public class Main {     public static void main(String[] args) throws Exception {         Scanner sc = new Scanner(System.in);         int n = sc.nextInt();         int m = sc.nextInt();                 int[] dp = new int[n+1];         for(int i=1;i<=n;i++){             if(i<m)                 dp[i] = 1;             else if(i == m)                 dp[i] = 2;             else                  dp[i] = dp[i-1] + dp[i-m];  

Buy And Sell Stocks - Infinite Transactions Allowed

 1. You are given a number n, representing the number of days. 2. You are given n numbers, where ith number represents price of stock on ith day. 3. You are required to print the maximum profit you can make if you are allowed infinite transactions. Note: There can be no overlapping transaction. One transaction needs to be closed (a buy followed by a sell) before opening another transaction (another buy) Input Format A number n .. n more elements Output Format A number representing the maximum profit you can make if you are allowed infinite transactions. Constraints 0 <= n <= 20 0 <= n1, n2, .. <= 10 Sample Input 9 11 6 7 19 4 1 6 18 4 Sample Output 30 Solution:  import java.io.*; import java.util.*; public class Main {     public static void main(String[] args) throws Exception {         // write your code here         Scanner sc = new Scanner(System.in);         int n = sc.nextInt();         int[] A = new int[n];         for(int i=0;i<n;i++)             A[i] =

Inverse Of An Array

1. You are given a number n, representing the size of array a. 2. You are given n numbers, representing elements of array a. 3. You are required to calculate the inverse of array a. For definition and constraints check this link https://www.pepcoding.com/resources/online-java-foundation/getting-started/inverse-of-a-number/ojquestion The only difference is the range of values is from 0 to n - 1, instead of 1 to n. Input Format Input is managed for you Output Format Output is managed for you   Constraints 0 <= n < 10^7 For more constraints check this https://www.pepcoding.com/resources/online-java-foundation/getting-started/inverse-of-a-number/ojquestion The only difference is the range of values is from 0 to n - 1, instead of 1 to n Sample Input 5 4 0 2 3 1 Sample Output 1 4 2 3 0 import java.io.*; import java.util.*; public class Main{   public static void display(int[] a){     StringBuilder sb = new StringBuilder();     for(int val: a){       sb.append(val + "\n");    

Next Greater Element To The Right

1. You are given a number n, representing the size of array a. 2. You are given n numbers, representing elements of array a. 3. You are required to "next greater element on the right" for all elements of array 4. Input and output is handled for you. "Next greater element on the right" of an element x is defined as the first element to right of x having value greater than x. Note: If an element does not have any element on it's right side greater than it, consider -1 as it's "next greater element on right" e.g. for the array [2 5 9 3 1 12 6 8 7] Next greater for 2 is 5 Next greater for 5 is 9 Next greater for 9 is 12 Next greater for 3 is 12 Next greater for 1 is 12 Next greater for 12 is -1 Next greater for 6 is 8 Next greater for 8 is -1 Next greater for 7 is -1 Input Format Input is managed for you Output Format Output is managed for you Constraints 0 <= n < 10^5 -10^9 <= a[i] <= 10^9 Sample Input 5 5 3 8 -2 7 Sample Output 8 8 -1

Inviting Online Applications for Joint Entrance Examination (Main) – 2022 | JEE Mains 2022

Jee Mains 2022 application forms for Session 1 have been released and eligible students can apply at the earliest. The application window is available from  01.03.2022 to 31.03.2022 (up to 05.00 P.M  ). ~ Image from Internet Important: JEE Mains Session 1 dates - 16, 17, 18, 19, 20 and 21 April 2022 The schedule for Session 1 and 2 for JEE Mains 2022 has been released by NTA on the official website:  https://jeemain.nta.nic.in/  What are Dates? ~ Image from Internet As per the official notice, the dates for examination under two sessions are as follows: Session 1 (April 2022)  16, 17, 18, 19, 20 and 21 April 2022  Session 2 (May 2022)    24, 25, 26, 27, 28 and 29 May 2022 The registration window is currently accessible till the 31st of the month.  ~ Image from Internet What NTA has changed for this year's JEE Mains?  Only 2 attempts Earlier 4 attempts were allowed in Mains exams Not Mandatory to appear in both exams  No correction facility will be given at any stage under any ci