Skip to main content

Posts

Showing posts from May, 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.. ..