This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* * A Bean array is defined to be an array where for every value n in the array, there is | |
* * also an element n-1 or n+1 in the array. | |
* * For example, {2, 10, 9, 3} is a Bean array because | |
* * 2 = 3-1 | |
* * 10 = 9+1 | |
* * 3 = 2 + 1 | |
* * 9 = 10 -1 | |
* * Other Bean arrays include {2, 2, 3, 3, 3}, {1, 1, 1, 2, 1, 1} and {0, -1, 1}. | |
* * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.basic.practice; | |
import lombok.extern.slf4j.Slf4j; | |
@Slf4j | |
public class OddNumberFollowedBySquareOfIt { | |
public static void main(String[] args) { | |
// int[] arrayOfNumbers = {1, 3, 4, 6, 5, 25}; | |
int[] arrayOfNumbers = {1, 3, 4, 6, 5, 0}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.basic.practice; | |
import lombok.extern.slf4j.Slf4j; | |
@Slf4j | |
public class CheckNFor2N { | |
public static void main(String[] args) { | |
// int[] arrayOfNumber = {1, 6, 4, 5, 3}; | |
int[] arrayOfNumber = {1, 9, 4, 5, 3}; | |
log.info("Checking if for any number N, the number 2N is not in an array. Return 1 for Yes and 0 for No.", arrayOfNumber); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.basic.practice; | |
import lombok.extern.slf4j.Slf4j; | |
@Slf4j | |
public class HighestOccurringDigitInNumber { | |
public static void main(String[] args) { | |
// int number = 1223412; | |
int number = 122341112; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* * Given a positive integer k, another positive integer n is said to have k-small factors if n can be | |
* * written as a product u*v where u and v are both less than k. For instance, 20 has 10-small factors | |
* * since both 4 and 5 are less than 10 and 4*5 = 20. | |
* * | |
* * (For the same reason, it is also true to say that 20 has 6-small factors, 7-small factors, 8-small factors, etc). | |
* * However, 22 does not have 10-small factors since the only way to factor 22 is as 22 = 2 * 11, and 11 is not less than 10. | |
* * | |
* * Write a function hasKSmallFactors with signature boolean hasKSmallFactors(int k, int n) | |
* * which returns true if n has k-small factors. The function should return false if either k or n is not |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* * A primeproduct is a positive integer that is the product of exactly two primes greater than 1. For | |
* * example, 22 is primeproduct since 22 = 2 times 11 and both 2 and 11 are primes greater than 1. | |
* * | |
* * Write a function named isPrimeProduct with an integer parameter that returns 1 if the parameter is a | |
* * primeproduct, otherwise it returns 0. Recall that a prime number is a positive integer with no factors | |
* * other than 1 and itself. | |
* * | |
* * You may assume that there exists a function named isPrime(int m) that returns 1 if its m is a prime | |
* * number. You do not need to write isPrime. You are allowed to use this function. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* * An array is called balanced if its even numbered elements (a[0], a[2], etc.) are even and its odd | |
* * numbered elements (a[1], a[3], etc.) are odd. | |
* * | |
* * Write a function named isBalanced that accepts an array of integers and returns 1 if the array is | |
* * balanced, otherwise it returns 0. | |
* * | |
* * Examples: {2, 3, 6, 7} is balanced since a[0] and a[2] are even, a[1] and a[3] are odd. {6, 7, 2, 3, 12} | |
* * is balanced since a[0], a[2] and a[4] are even, a[1] and a[3] are odd. | |
* * {7, 15, 2, 3} is not balanced since a[0] is odd. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* * An array with an odd number of elements is said to be centered if all elements (except the middle one) | |
* * are strictly greater than the value of the middle element. | |
* * | |
* * Note that only arrays with an odd number of elements have a middle element. | |
* * | |
* * Write a function named isCentered that accepts an integer array and returns 1 if it is a centered array, | |
* * otherwise it returns 0. | |
* * | |
* * Examples: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* * Get Maximum Element value from the given array. | |
*/ | |
package com.basic.practice; | |
import lombok.extern.slf4j.Slf4j; | |
@Slf4j | |
public class MaxNumberInArray { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* * An array is defined to be complete if the conditions (a), (d) and (e) below hold. | |
* * a. The array contains even numbers | |
* * b. Let min be the smallest even number in the array. | |
* * c. Let max be the largest even number in the array. | |
* * d. min does not equal max | |
* * e. All numbers between min and max are in the array | |
* * | |
* * For example {-5, 6, 2, 3, 2, 4, 5, 11, 8, 7} is complete because |