Maximum Possible Value of an Integer in Java

AmitDiwan
Updated on 17-Aug-2020 08:50:41

3K+ Views

The MAX_VALUE is used to find the maximum possible value for an integer in Java. Let us see an example −Example Live Demopublic class Demo{    public static void main(String[] args){       System.out.println("The type is");       System.out.println(Integer.TYPE);       System.out.println("The size is");       System.out.println(Integer.SIZE);       System.out.println("The max value of integer is");       System.out.println(Integer.MAX_VALUE);    } }OutputThe type is int The size is 32 The max value of integer is 2147483647A class named Demo uses the Integer class and gives the various characteristics of the Integer class such as type, size ... Read More

Maximum Number of Candies That Can Be Bought in C

Sunidhi Bansal
Updated on 17-Aug-2020 08:50:11

847 Views

We are given an array of candies[] of length stored in ‘size’. Each element candies[i] has a number for candies of type i.The goal is to buy as many candies as possible for any amount of money. The conditions are as given −If you purchase X[i] of type i (0

Maximum Number of 2x2 Squares Inside a Right Isosceles Triangle in C

Sunidhi Bansal
Updated on 17-Aug-2020 08:48:50

814 Views

We are given a right isosceles triangle. Isosceles triangle is the one which has two sides of equal length. Right triangle is the one which has height(ag in fig.) and base (dg in fig.) perpendicular to each other. The goal is to find the maximum number of squares that can fit into this right isosceles triangle of side 2 sq units. The sides base or height (both equal) are taken as input. No. of squares is output.Refer to the below figure to understand the problemThe given triangle of height ag and base gd has 3 squares of side 2 each. ... Read More

Maximum Number of Contiguous Prime Numbers in an Array in C++

Sunidhi Bansal
Updated on 17-Aug-2020 08:46:30

500 Views

We are given with an array of prime numbers, arranged in random order. The size of the array is N. The goal is to find the longest sequence of contiguous prime numbers in the array.Prime number is the one which has only two factors, 1 and the number itself. 1, 2, 3, 5, 7, 11, 13….are prime numbers whereas 4, 6, 8, 9, 10….20 are non-prime. Every non-prime number has more than 2 factors. Let’s understand with examples.Input − Arr[] = { 1, 3, 5, 2, 6, 7, 13, 4, 9, 10Output − 3Explanation − The prime numbers in the ... Read More

Maximum Consecutive Repeating Character in String in C++

Sunidhi Bansal
Updated on 17-Aug-2020 08:44:50

2K+ Views

We are given a string of alphabets. The task is to find the character which has the longest consecutive repetitions occurring in string. Let’s understand with examples.Input− String[] = “abbbabbbbcdd”Output − bExplanation − In the above string, the longest consecutive sequence is of character ‘b’. Count of consecutive b’s is 4.Input− String[] = “aabbcdeeeeed”Output − bExplanation − In the above string, the longest consecutive sequence is of character ‘e’. Count of consecutive e’s is 5.Approach used in the below program is as followsThe character array string1[] is used to store the string of alphabets.Function maxRepeating(char str[], int n) takes two ... Read More

Maximum Consecutive One’s or Zeros in a Binary Circular Array in C++

Sunidhi Bansal
Updated on 17-Aug-2020 08:43:21

800 Views

We are given with a circular array. Circular array is the array for which we consider the case that the first element comes next to the last element. It is used to implement queues. So we have to count the maximum no. of consecutive 1’s or 0’s in that array.Let’s understand with examples.Input − Arr[] = { 1, 1, 0, 1, 0, 1, 0, 1, 1, 1 }Output − Maximum consecutive 1’s are 5. Or Maximum consecutive 0’s is 1.Explanation − From Arr[] index 7 to 9 and then indexes 0 and 1. 1’s are 5. No consecutive 0’s but ... Read More

Java Program for Longest Palindromic Subsequence

AmitDiwan
Updated on 17-Aug-2020 08:42:15

253 Views

For longest Palindromic subsequence, the Java code is as follows −Example Live Demopublic class Demo{    static String longest_seq(String str_1, String str_2){       int str_1_len = str_1.length();       int str_2_len = str_2.length();       char str_1_arr[] = str_1.toCharArray();       char str_2_arr[] = str_2.toCharArray();       int L[][] = new int[str_1_len + 1][str_2_len + 1];       for (int i = 0; i 0){          if (str_1_arr[i - 1] == str_2_arr[j - 1]){             longest_seq[my_index - 1] = str_1_arr[i - 1];       ... Read More

Maximum Bishops on an N x N Chessboard in C++

Sunidhi Bansal
Updated on 17-Aug-2020 08:39:16

468 Views

We are given an input N which denotes the size of the chessboard. The task here is to find for any value of N, how many bishops can be placed on the NXN chessboard such that no two bishops can attack each other. Let’s understand with examples.Input − N=2Output− Maximum bishops that can be placed on N*N chessboard − 2 ( as shown above )Explanation − As depicted above the only non-contradictory positions are where the bishops are placed. Bishops at-most for 2X2 chessboard.Input − N=5Output− Maximum bishops that can be placed on N*N chessboard: 8 ( as shown above ... Read More

Count Number of 1s in the Array After N Moves in C

Sunidhi Bansal
Updated on 17-Aug-2020 08:37:01

469 Views

We are given an array of size N. The array has all 0’s initially. The task is to count the no. of 1’s in the array after N moves. Each Nth move has a rule associated. The rules are −1st Move − Change element at positions 1, 2, 3, 4…………..2nd Move − Change element at positions 2, 4, 6, 8…………..3rd Move − Change element at positions 3, 6, 9, 12…………..Count the number of 1’s in the last array.Let’s understand with examples.Input Arr[]={ 0, 0, 0, 0 } N=4Output Number of 1s in the array after N moves − 2Explanation − Array after ... Read More

Maximum Binomial Coefficient Term Value in C

Sunidhi Bansal
Updated on 17-Aug-2020 08:33:47

259 Views

We are given with a positive integer ‘N’. We have to find the maximum coefficient term in all binomial coefficients.The binomial coefficient series is nC0, nC1, nC2, …., nCr, …., nCn-2, nCn-1, nCnfind the maximum value of nCr.nCr = n! / r! * (n - r)!Input − N=4Output − Maximum Coefficient − 6Explanation − 4C0= 1, 4C1 = 4, 4C2 = 6, 4C3 = 4, 4C4 = 1Therefore, the maximum coefficient is 6 in this case.Input − N=5Output − Maximum Coefficient − 10Explanation − 5C0= 1, 5C1 = 5, 5C2 =10, 5C3 = 10, 5C4 = 5, 5C5 = 1Therefore, ... Read More

Advertisements