├── Nim game ├── Odd or even ├── Add digits ├── a num after a double reversal ├── Calculate delayed arrival time ├── matrix diagonal sum ├── armstrong number ├── Reverse integer ├── ugly number ├── Three consecutive odds ├── Reverse the given string ├── palindrome number ├── First and last value in array ├── Even numbers in array ├── minimum cost to move chips to ├── Even Index in Array ├── Odd num in array ├── Rotate array ├── Sum of num 2d array ├── Array value greaterthan given value ├── count of vowel ├── Array values greaterthan10 ├── Sum of even numbers in array ├── Sum of rows in 2d ├── Sum of column in 2D ├── To find targeted value └── Maximum value in each row /Nim game: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean canWinNim(int n) { 3 | return n%4 !=0 ; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /Odd or even: -------------------------------------------------------------------------------- 1 | class Solution { 2 | static boolean isEven(int n) { 3 | // code here 4 | return (n&1)==0; 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Add digits: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int addDigits(int num) { 3 | if(num==0) return 0; 4 | return num%9 == 0? 9:num%9; 5 | 6 | 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /a num after a double reversal: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isSameAfterReversals(int num) { 3 | if( num ==0) return true; 4 | return num%10 !=0; 5 | 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Calculate delayed arrival time: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findDelayedArrivalTime(int arrivalTime, int delayedTime) { 3 | return (arrivalTime+delayedTime) %24; 4 | 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /matrix diagonal sum: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int diagonalSum(int[][] arr) { 3 | int n= arr.length; 4 | int sum = 0; 5 | for(int i=0; i Integer.MAX_VALUE){ 9 | return 0; 10 | } 11 | return (int)rev; 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ugly number: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isUgly(int n) { 3 | if(n<=0) return false; 4 | while(n%2==0){ 5 | n=n/2; 6 | } 7 | while(n%3==0){ 8 | n=n/3; 9 | } 10 | while(n%5==0){ 11 | n=n/5; 12 | } 13 | return n==1; 14 | 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Three consecutive odds: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean threeConsecutiveOdds(int[] arr) { 3 | for (int i = 0; i < arr.length - 2; i++) { 4 | if (arr[i] % 2 != 0 && arr[i+1] % 2 != 0 && arr[i+2] % 2 != 0) { 5 | return true; 6 | } 7 | } 8 | return false; 9 | } 10 | // public static void main(String args[]){ 11 | // S 12 | // } 13 | 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Reverse the given string: -------------------------------------------------------------------------------- 1 | package string_based_problems; 2 | import java.util.*; 3 | public class Reverse { 4 | 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | String s = sc.nextLine(); 8 | //String rev=" "; 9 | for( int i= s.length() - 1; i>=0; i--) { 10 | char ch = s.charAt(i); 11 | System.out.print(ch); 12 | //rev += ch; 13 | } 14 | //System.out.print(rev); 15 | 16 | 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /palindrome number: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isPalindrome(int n) { 3 | if(n<0){ 4 | return false; 5 | } 6 | int rev = 0; 7 | int s = n; 8 | while(n != 0){ 9 | rev = rev*10 +(n%10); 10 | n = n/10; 11 | } 12 | if(rev == s){ 13 | return true; 14 | } 15 | return false; 16 | 17 | 18 | } 19 | } 20 | 21 | 22 | -------------------------------------------------------------------------------- /First and last value in array: -------------------------------------------------------------------------------- 1 | package array_based_problem; 2 | import java.util.Scanner; 3 | 4 | public class FirstLast { 5 | 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int n = sc.nextInt(); 9 | int arr[] = new int[n]; 10 | for(int i = 0; i x) { 15 | System.out.println(arr[i]); 16 | } 17 | 18 | } 19 | // TODO Auto-generated method stub 20 | 21 | } 22 | 23 | 24 | // TODO Auto-generated method stub 25 | 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /count of vowel: -------------------------------------------------------------------------------- 1 | package string_based_problems; 2 | import java.util.*; 3 | 4 | public class Vowel { 5 | 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | String s = sc.nextLine(); 9 | int count=0; 10 | for(int i=0; i10) { 18 | 19 | count++; 20 | 21 | 22 | } 23 | } 24 | System.out.println(count); 25 | 26 | 27 | // TODO Auto-generated method stub 28 | 29 | 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Sum of even numbers in array: -------------------------------------------------------------------------------- 1 | package array_based_problem; 2 | 3 | import java.util.Scanner; 4 | 5 | public class SumOfEven { 6 | 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | int n = sc.nextInt(); 10 | int sum =0; 11 | int arr[] = new int[n]; 12 | for(int i = 0;i