Posts

Showing posts from 2021

leetcode Max Area of Island Solution (Max Area of Island) (leetcode june 2021 challenge)

Image
Max Area of Island You are given an  m x n  binary matrix  grid . An island is a group of  1 's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water. The area of an island is the number of cells with a value  1  in the island. Return  the maximum area of an island in  grid . If there is no island, return  0 .   Example 1:   Example 1: Input: grid = [[0,0,1,0,0,0,0,1,0,0,0,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,1,1,0,1,0,0,0,0,0,0,0,0],[0,1,0,0,1,1,0,0,1,0,1,0,0],[0,1,0,0,1,1,0,0,1,1,1,0,0],[0,0,0,0,0,0,0,0,0,0,1,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,0,0,0,0,0,0,1,1,0,0,0,0]] Output: 6 Explanation: The answer is not 11, because the island must be connected 4-directionally.   Example 2: Input: grid = [[0,1,1,1,0,0,0,0]] Output: 3 Constraints: ·      ...

codeforces 45A Solution A. Codecraft lll (codeforces 45A) (rank 900*)

 45A. Codecraft ll l Problem Link: https://codeforces.com/problemset/problem/45/A Solution 1: import   java . util . Scanner ; public   class   A45  {      public   static   Scanner   scn  =  new   Scanner ( System . in );      public   static   String []  str  = {  "January" ,  "February" ,  "March" ,  "April" ,  "May" ,  "June" ,  "July" ,  "August" ,              "September" ,  "October" ,  "November" ,  "December"  };      public   static   int   nextIdx ( int   currIdx ,  int   change ) {          return  ( currIdx  +  change ) %  12 ;     }      public   static   int  ...

codeforces 282A Solution A. Bit++ (codeforces 282A) (rank 800*)

 282A. Bit++ Problem Link: https://codeforces.com/problemset/problem/282/A Solution 1: import   java . util .*; import java.util.Scanner; public class A282 { public static int calculateFinalValue ( int n, Scanner scn) { int ans = 0 ; for ( int i = 0 ; i < n; i++) { String operation = scn.next(); if (operation.contains( "+" )) { ans++; } else { ans--; } } return ans; } public static void main (String[] args) { Scanner scn = new Scanner (System.in); int n = scn.nextInt(); System.out.println(calculateFinalValue(n, scn)); scn.close(); // Always close the scanner to avoid resource leaks } }

codeforces 263A Solution A. Beautiful Matrix (codeforces 263A) (rank 800*)

  263A.  Beautiful Matrix Problem Link: https://codeforces.com/problemset/problem/263/A Solution 1: import   java . util .*; public   class   A263  {      public   static   Scanner   scn  =  new   Scanner ( System . in );      public   static   void   input ( int [][]  arr ) {          for  ( int   i  =  0 ;  i  <  5 ;  i ++)              for  ( int   j  =  0 ;  j  <  5 ;  j ++)                  arr [ i ][ j ] =  scn . nextInt ();     }      public   static   int   TotalMoves ( int [][]  arr ) {     ...

codeforces 43D Solution D.Journey (codeforces 43D) (rank 2000*)

43D. Journey Problem Link: "https://codeforces.com/problemset/problem/43/D" Solution 1: import   java . util .*; public   class   traveseKing  {      public   static   Scanner   scn  =  new   Scanner ( System . in );        public   static   int   counter  =  0 ;        public   static   boolean   isTelepoter ( int [][]  arr ,  int   i ,  int   j ,  int   n ,  int   m ,  int   count ,  ArrayList < int []>  al ,              int [][]  dirEven ,  int [][]  dirOdd ) {          if  ( n  ==  1  &&  m  ==  1 ) {              System . out . pr...

codeforces 158A Solution Next Round (codeforces 158A) (rank 800*)

158A. Next Round Problem Link:  https://codeforces.com/problemset/problem/158/A Solution 1: import   java . util .*; public   class   A158  {      public   static   Scanner   scn  =  new   Scanner ( System . in );      public   static   int   passedStudent ( int []  arr ,  int   value ,  int   k ) {          int   counter  =  0 ;          for  ( int   i  =  0 ;  i  <  arr . length ;  i ++) {              if  ( value  <=  arr [ i ] &&  arr [ i ] >  0 )                  counter ++;        ...