Skip to content

anderson-bastos/30DaysOfCodeHackerHank

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

30 Days of Code

Every day for 30 days, you will receive an email posing a challenge for you to code, solve, and submit the solution.

Day 0 - Hello, World.

To complete this challenge, you must save a line of input from stdin to a variable, print Hello, World. on a single line, and finally print the value of your variable on a second line.

Day 1 - Data Types

Complete the code in the editor below. The variables i,d, and s are already declared and initialized for you. You must:

  1. Declare 3 variables: one of type int, one of type double, and one of type String.
  2. Read 3 lines of input from stdin (according to the sequence given in the Input Format section below) and initialize your variables.
  3. Use the + operator to perform the following operations:
  • Print the sum of plus your int variable on a new line.
  • Print the sum of plus your double variable to a scale of one decimal place on a new line.
  • Concatenate with the string you read as input and print the result on a new line.
Solution:
int i = 4;
double d = 4.0;
String s = "HackerRank ";

Scanner scan = new Scanner(System.in);
/* Declare second integer, double, and String variables. */
 int secondInteger = 0;
double secondDouble = 0;
 String secondString = ""; 

 /* Read and save an integer, double, and String to your variables.*/
 // Note: If you have trouble reading the entire String, please go back and review the Tutorial closely.        
 secondInteger = Integer.parseInt(scan.nextLine().trim());
 secondDouble = Double.parseDouble(scan.nextLine().trim());
 secondString = scan.nextLine();

/* Print the sum of both integer variables on a new line. */
System.out.println(i+secondInteger);

/* Print the sum of the double variables on a new line. */
System.out.println(d+secondDouble);

/* Concatenate and print the String variables on a new line; 
the 's' variable above should be printed first. */
System.out.println(s+secondString);
scan.close();

Day 2 - Operators

Given the meal price (base cost of a meal), tip percent (the percentage of the meal price being added as tip), and tax percent (the percentage of the meal price being added as tax) for a meal, find and print the meal's total cost.

Note: Be sure to use precise valuaes for your calculations, or you may end up with an incorrectly rounded result!

Solution:
public static double totalCoast(double mealCost, int tipPercent, int taxPercent) {
	double tip = calculatePercentage(mealCost, tipPercent);
	double tax = calculatePercentage(mealCost, taxPercent);		
	return Math.round((mealCost + tip + tax));
}

private static double calculatePercentage(double mealCost, int valuePercentage) {
	return mealCost * (valuePercentage/100.0);
}

Day 3 - Intro to Conditional Statements

Given an integer, n, perform the following conditional actions:

  • If n is odd, print Weird
  • If n is even and in the inclusive range of 2 to 5 , print Not Weird
  • If n is even and in the inclusive range of 6 to 20 , print Weird
  • If n is even and greater than 20 , print Not Weird Complete the stub code provided in your editor to print whether or not n is weird.
Solution:
public static final String WEIRD = "Weird";
public static final String NOT_WEIRD = "Not Weird";

private static boolean isOddNumber(int number) {
	return number % 2 != 0;
}

private static boolean contains(IntStream rangeInterval, final int key) {     
	return rangeInterval.anyMatch(x -> x == key);
}

public static String checkIfWeirdNumber(int number) {
	Boolean isOddNumber = isOddNumber(number);		
	if(isOddNumber)
		return WEIRD;
	
	if(contains(IntStream.range(2, 6), number))
		return NOT_WEIRD;
	
	if(contains(IntStream.range(6, 21), number))
		return WEIRD;
	
	return NOT_WEIRD;
}

Day 4 - Arrays

Write a Person class with an instance variable, age , and a constructor that takes an integer, initialAge , as a parameter. The constructor must assign to after confirming the argument passed as initialAge is not negative; if a negative argument is passed as initialAge , the constructor should set age to 0 and print Age is not valid, setting age to 0.. In addition, you must write the following instance methods:

  1. yearPasses() should increase the age instance variable by 1.
  2. amIOld() should perform the following conditional actions:
  • If age < 13, print You are young..
  • If age >= 13 and age < 18 , print You are a teenager..
  • Otherwise, print You are old.. To help you learn by example and complete this challenge, much of the code is provided for you, but you'll be writing everything in the future. The code that creates each instance of your Person class is in the main method. Don't worry if you don't understand it all quite yet!
Solution:
private int age;

public static final String YOUNG = "You are young.";
public static final String TEENAGER = "You are a teenager.";
public static final String OLD = "You are old.";

private static IntFunction<String> youngFunction = x -> x >= 13 && x < 18 ? TEENAGER : OLD;
private static IntFunction<String> ageFunction = x -> x < 13 ? YOUNG : youngFunction.apply(x);
	
public DayFour(int initialAge) {		
	if(initialAge < 0) {
		this.age = 0;
		System.out.println("Age is not valid, setting age to 0.");
	}
	this.age = initialAge;
}

public String checkamIOld() {
	return ageFunction.apply(this.age);
}

public void amIOld() {		
	System.out.println(checkamIOld());
}	

public void yearPasses() {
	this.age++;
}

public static void main(String[] args) {
	DayFour dayFour = new DayFour(10);	
	dayFour.amIOld();
}

Day 5 - Loops

Given an integer, n , print its first 10 multiples. Each multiple n x i (where 1 <= i <= 10 ) should be printed on a new line in the form: n x i = result.

Solution:
public static void loopMultiples(int number) {
	IntStream.range(1, 11).forEach(x -> System.out.printf("%d x %d = %d %n", number, x, number*x));
}

Day 6 - Let's Review

Given a string, S , of length N that is indexed from 0 to N-1, print its even-indexed and odd-indexed characters as 2 space-separated strings on a single line (see the Sample below for more detail).

Note: is considered to be an even index.

Solution:
public static void formatSringArr(String[] text) {
	Arrays.stream(text).forEach(x -> System.out.println(formatSring(x)));
}

public static String formatSring(String text) {
	StringBuilder evenText = new StringBuilder();
	StringBuilder oddText = new StringBuilder();
	int textLength = text.length();

	for (int i = 0; i < textLength; i++) {
		if (i % 2 == 0)
			evenText.append(text.charAt(i));
		else
			oddText.append(text.charAt(i));
	}
	return String.format("%s %s", evenText.toString(), oddText.toString());
}

private static final Scanner scanner = new Scanner(System.in);

public static void main(String[] args) {
	int llistCount = scanner.nextInt();
	scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

	String[] arr = new String[llistCount];
	for (int i = 0; i < llistCount; i++) {
		String element = scanner.nextLine();
		arr[i] = element;
	}
	formatSringArr(arr);
}

Day 7 - Arrays

Given an array, A, of N integers, print A's elements in reverse order as a single line of space-separated numbers.

Solution:
public static int[] inverseArray(int[] array) {
	int length = array.length;
	int mid = length / 2;
	for (int i = 0; i < mid; i++) {
		int aux = array[length - 1 - i];
		array[length - 1 - i] = array[i];
		array[i] = aux;
	}
	return array;
}

Day 8 - Dictionaries and Maps

Given n names and phone numbers, assemble a phone book that maps friends' names to their respective phone numbers. You will then be given an unknown number of names to query your phone book for. For each name queried, print the associated entry from your phone book on a new line in the form name=phoneNumber; if an entry for name is not found, print Not found instead.

Solution:
static HashMap<String, Integer> phoneBook = new HashMap<>();
public static void insertContact(String name, int phone) {
  phoneBook.put(name, phone);
}
public static String findContact(String s) {
	String result = "Not found";
	Integer phone = phoneBook.get(s);
	if(phone != null) 
		result = String.format("%s=%d", s, phone);
	return result; 
}
public static void main(String []args) {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();        
    for(int i = 0; i < n; i++){
        String name = in.next();
        int phone = in.nextInt();
        insertContact(name, phone);
    }        
    while(in.hasNext()){
        String s = in.next();
        System.out.println(findContact(s));
    }
    in.close();
}

Day 9 - Recursion 3

Write a factorial function that takes a positive integer, N as a parameter and prints the result N! of (N factorial).

Solution:
static int factorial(int n) {
  if(n <= 1)
	return 1;
  return n * factorial(n-1);
}

Day 10 - Binary Numbers

Given a base-10 integer, n , convert it to binary (base-2). Then find and print the base-10 integer denoting the maximum number of consecutive 1's in n's binary representation.

Solution:
public static int calculateConsecutiveOnesBinaryNumber(int number) {
	String binaryNumber = Integer.toBinaryString(number);
	int count = 0;
	int maxOnes = 1;
	for (int i = 0; i < binaryNumber.length(); i++) {
		if(binaryNumber.charAt(i) == '1'){
			++count;
			if(count > maxOnes) 
				maxOnes = count;
			continue;
		}
		count=0;
	}
	return maxOnes;
}

Day 11 - 2D Arrays

Calculate the hourglass sum for every hourglass in A, then print the maximum hourglass sum.

Solution:
public static int maxArray2D(int[][] arr) {		
	int sumElements = 0;
   	int sumMax = 0;
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			sumElements = sumElementsArray(arr, i, j);
            if(sumElements > sumMax || (i==0 && j==0))
            	sumMax = sumElements;
		}			
	}
	return sumMax;
}

private static int sumElementsArray(int[][] arr, int i, int j) {
	return arr[i][j] + arr[i][j+1] + arr[i][j+2]
	        + arr[i+1][j+1] + arr[i+2][j] + arr[i+2][j+1]
	        + arr[i+2][j+2];
}

Day 12 - Inheritance

You are given two classes, Person and Student, where Person is the base class and Student is the derived class. Completed code for Person and a declaration for Student are provided for you in the editor. Observe that Student inherits all the properties of Person.

Complete the Student class by writing the following:

  • A Student class constructor, which has 4 parameters:
    1. A string, firstName
    2. A string, lastName
    3. An integer, id
    4. An integer array (or vector) of test scores, scores.
  • A char calculate() method that calculates a Student object's average and returns the grade character representative of their calculated average:

Solution:
public class Person {	
	protected String firstName;
	protected String lastName;
	protected int idNumber;
	
	public Person(String firstName, String lastName, int identification) {
		this.firstName = firstName;
		this.lastName = lastName;
		this.idNumber = identification;
	}
	
	public void printPerson() {
		System.out.println("Name: " + lastName + ", " + firstName + "\nID: " + idNumber);
	}
}

public class Student extends Person {	
	private int[] testScores;
	
	public Student(String firstName, String lastName, int identification, int[] testScores) {
		super(firstName, lastName, identification);
		this.testScores = testScores;
	}
	
	private double calculateAveragePoints() {
		int scores = this.testScores.length;
		return Arrays.stream(this.testScores).sum()/scores;
	}

	private char getScale(double averageScores) {
		if(averageScores >= 90 && averageScores <= 100)
			return 'O';
		if(averageScores >= 80 && averageScores <= 90)
			return 'E';
		if(averageScores >= 70 && averageScores <= 80)
			return 'A';
		if(averageScores >= 55 && averageScores <= 70)
			return 'P';
		if(averageScores >= 40 && averageScores <= 55)
			return 'D';		
		return 'T';
	}
	
	public char calculate() {
		double averageScores = calculateAveragePoints();
		return getScale(averageScores);
	}
}

Day 13 - Abstract Classes

Given a Book class and a Solution class, write a MyBook class that does the following:

  • Inherits from Book

  • Has a parameterized constructor taking these 3 parameters:

    1. string title
    2. string author
    3. string price
  • Implements the Book class' abstract display() method so it prints these lines:

    1. Title: a space, and then the current instance's title
    2. Author: a space, and then the current instance's author
    3. Price: a space, and then the current instance's price

    Note: Because these classes are being written in the same file, you must not use an access modifier (e.g.: ) when declaring MyBook or your code will not execute.

Solution:
public abstract class Book {	
    public String title;
    public String author;
    
    Book(String title, String author) {
        this.title = title;
        this.author = author;
    }    
    abstract void display();
}

public class MyBook extends Book {
	
    public int price = 0;
	
    MyBook(String title, String author, int price) {
       super(title, author);
       this.price = price;
    }

    @Override
    void display() {
        System.out.println("Title: " + this.title);
        System.out.println("Author: " + this.author);
        System.out.println("Price: " + this.price);
    }
}

Day 14 - Scope

Complete the Difference class by writing the following:

  • A class constructor that takes an array of integers as a parameter and saves it to the elements instance variable.
  • A computeDifference method that finds the maximum absolute difference between any 2 numbers in N and stores it in the maximumDifference instance variable.
Solution:
public class Difference {

	private int[] elements;
	public int maximumDifference;

	public Difference(int[] elements) {
		this.elements = elements;
		this.maximumDifference = 0;
	}

	public void computeDifference() {
		int n = elements.length;
		for (int i = 0; i < n; i++) {
			for (int j = 1; j < n; j++) {
				int difference = calculateDifference(elements[i], elements[j]);
				if(difference > maximumDifference)
					maximumDifference = difference;
			}
		}
	}
	
	private int calculateDifference(int i, int j) {
		return i > j ? i - j : j - i;
	}
}

Day 15 - Linked List

Complete the insert function in your editor so that it creates a new Node (pass data as the Node constructor argument) and inserts it at the tail of the linked list referenced by the head parameter. Once the new node is added, return the reference to the head node.

Note: If the argument passed to the insert function is null, then the initial list is empty.

Solution:
public static Node insert(Node head, int data) {
	if (head == null)
		return new Node(data);
	
	if(head.next == null) {
		head.next = new Node(data);
	} else {
		Node current = head.next;
		while(current.next != null)
			current = current.next;
		current.next = new Node(data);
	}
	return head;
}

Day 16 - Exceptions - String to Integer

Read a string, S , and print its integer value; if S cannot be converted to an integer, print Bad String.

Note: You must use the String-to-Integer and exception handling constructs built into your submission language. If you attempt to use loops/conditional statements, you will get a 0 score.

Solution:
public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	String S = in.next();
	in.close();
	try {
		int number = Integer.parseInt(S);
		System.out.println(number);
	} catch (NumberFormatException nfe) {
		System.out.println("Bad String.");
	}
}

Day 17 - More Exceptions

Write a Calculator class with a single method: int power(int,int). The power method takes two integers, n and p , as parameters and returns the integer result of . If either n or p is negative, then the method must throw an exception with the message:n and p should be non-negative.

Solution:
class Calculator {
	
	public int power(int n, int p) {
		if (n < 0 || p < 0)
			throw new IllegalArgumentException("n and p should be non-negative");
		return calculatePower(n, p);
	}

	private int calculatePower(int n, int p) {
		if (p == 0)
			return 1;
		return n * calculatePower(n, p - 1);
	}
}

Day 18 - Queues and Stacks

A palindrome is a word, phrase, number, or other sequence of characters which reads the same backwards and forwards. Can you determine if a given string, s , is a palindrome?

To solve this challenge, we must first take each character in s, enqueue it in a queue, and also push that same character onto a stack. Once that's done, we must dequeue the first character from the queue and pop the top character off the stack, then compare the two characters to see if they are the same; as long as the characters match, we continue dequeueing, popping, and comparing each character until our containers are empty (a non-match means s isn't a palindrome).

Solution:
public class Palindrome {
	
	Queue<Character> queue;
	Stack<Character> stack;
	
	public Palindrome() {
		queue = new LinkedList<>();
		stack = new Stack<>();
	}

	public void pushCharacter(char ch) {
		stack.push(ch);
	}
	
	public void enqueueCharacter(char ch) {
		queue.add(ch);
	}
	
	public char popCharacter() {
		return stack.pop();	
	}
	
	public char dequeueCharacter() {
		 return queue.poll();
	}
}

Day 19 - Interfaces

The AdvancedArithmetic interface and the method declaration for the abstract divisorSum(n) method are provided for you in the editor below.

Complete the implementation of Calculator class, which implements the AdvancedArithmetic interface. The implementation for the divisorSum(n) method must return the sum of all divisors of n.

Solution:
interface AdvancedArithmetic{
   int divisorSum(int n);
}

class Calculator implements AdvancedArithmetic {
    public int divisorSum(int n) {
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            if(n % i == 0)
                sum += i;
        }
        return sum;
    }
}

Day 20 - Sorting

Given an array, a , of size n distinct elements, sort the array in ascending order using the Bubble Sort algorithm above. Once sorted, print the following 3 lines:

  1. Array is sorted in numSwaps swaps.
    where is the number of swaps that took place.
  2. First Element: firstElement
    where is the first element in the sorted array.
  3. Last Element: lastElement
    where is the last element in the sorted array.

Hint: To complete this challenge, you will need to add a variable that keeps a running tally of all swaps that occur during execution.

Solution:
public static int getNumberOfSwaps(int[] arr) {
    int n = arr.length;
    int numberTotalOfSwaps = 0;
    for (int i = 0; i < n; i++) {
        int numberOfSwaps = 0;
        for (int j = 0; j < n - 1; j++) {
            if (arr[j] > arr[j + 1]) {
                int aux = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = aux;
                numberOfSwaps++;
            }
        }
        if (numberOfSwaps == 0)
            break;
        numberTotalOfSwaps += numberOfSwaps;
    }
    return numberTotalOfSwaps;
}

Day 21 - Generics

Write a single generic function named printArray; this function must take an array of generic elements as a parameter (the exception to this is C++, which takes a vector). The locked Solution class in your editor tests your function.

Note: You must use generics to solve this challenge. Do not write overloaded functions.

Solution:
class Printer <T> {
    void printArray(T[] printer) {
        for (int i = 0; i < printer.length; i++) {
            System.out.println(printer[i]);
        }
    }
}

Day 22 - Binary Search Trees

The height of a binary search tree is the number of edges between the tree's root and its furthest leaf. You are given a pointer, root , pointing to the root of a binary search tree. Complete the getHeight function provided in your editor so that it returns the height of the binary search tree.

Solution:
public static int getHeight(Node root) {
	if(root == null)
		return -1;
	return 1 + Math.max(getHeight(root.left), getHeight(root.right));
}

Day 23 - BST Level-Order Traversal

A level-order traversal, also known as a breadth-first search, visits each level of a tree's nodes from left to right, top to bottom. You are given a pointer, root , pointing to the root of a binary search tree. Complete the levelOrder function provided in your editor so that it prints the level-order traversal of the binary search tree.

Hint: You'll find a queue helpful in completing this challeng

Solution:
static void levelOrder(Node root) {
	int h = height(root);
	int i;
	for (i = 1; i <= h; i++)
		printGivenLevel(root, i);
}

static int height(Node root) {
	if (root == null)
		return 0;
	
	int leftHeight = height(root.left);
	int rightHeight = height(root.right);

	if (leftHeight > rightHeight)
		return (leftHeight + 1);			
	return (rightHeight + 1);		
}

static void printGivenLevel(Node root, int level) {
	if (root == null)
		return;
	if (level == 1)
		System.out.print(root.data + " ");
	else if (level > 1) {
		printGivenLevel(root.left, level - 1);
		printGivenLevel(root.right, level - 1);
	}
}

Day 24 - More Linked Lists

A Node class is provided for you in the editor. A Node object has an integer data field, data , and a Node instance pointer, next , pointing to another node (i.e.: the next node in a list).

A removeDuplicates function is declared in your editor, which takes a pointer to the head node of a linked list as a parameter. Complete removeDuplicates so that it deletes any duplicate nodes from the list and returns the head of the updated list.

Note: The head pointer may be null, indicating that the list is empty. Be sure to reset your next pointer when performing deletions to avoid breaking the list.

Solution:
public static Node removeDuplicates(Node head) {
	Node previus = head;
	Node current = null;		
    while (previus != null && previus.next != null) {
        current = previus;
        while (current.next != null) {
            if (previus.data == current.next.data) {
                current.next = current.next.next;
            } else { 
            	current = current.next;                    
            } 
        } 
        previus = previus.next;            
    } 
	return head;
}

Day 25 - Running Time and Complexity

A prime is a natural number greater than that has no positive divisors other than and itself. Given a number, , determine and print whether it's or .

Note: If possible, try to come up with a primality algorithm, or see what sort of optimizations you come up with for an algorithm. Be sure to check out the Editorial after submitting your code!

Solution:
private static String checkNumber(int number) {
	boolean numberIsPrime = numberIsPrime(number);
	if (numberIsPrime)
		return "Prime";
	return "Not prime";
}

private static boolean numberIsPrime(int number) {
	if (number <= 1)
		return false;
	if (number <= 3)
		return true;
	if (number % 2 == 0 || number % 3 == 0)
		return false;
	for (int i = 5; i * i <= number; i = i + 6)
		if (number % i == 0 || number % (i + 2) == 0)
			return false;
	return true;
}

Day 26 - Nested Logic

Your local library needs your help! Given the expected and actual return dates for a library book, create a program that calculates the fine (if any). The fee structure is as follows:

  1. If the book is returned on or before the expected return date, no fine will be charged (i.e.: .
  2. If the book is returned after the expected return day but still within the same calendar month and year as the expected return date, .
  3. If the book is returned after the expected return month but still within the same calendar year as the expected return date, the .
  4. If the book is returned after the calendar year in which it was expected, there is a fixed fine of .
Solution:
public static int getHackosByDateReceived(LocalDate dateExpected, LocalDate dateReceived) {
	if (dateExpected.compareTo(dateReceived) > 0)
		return 0;

	int yearDiff = dateReceived.getYear() - dateExpected.getYear();
	if (yearDiff > 0)
		return 10000;

	int monthDiff = dateReceived.getMonthValue() - dateExpected.getMonthValue();
	if (monthDiff > 0)
		return 500 * monthDiff;

	int dayDiff = dateReceived.getDayOfMonth() - dateExpected.getDayOfMonth();
	if (dayDiff > 0)
		return 15 * dayDiff;
	return dayDiff;
}

Day 27 - Testing

Your company needs a function that meets the following requirements:

  • For a given array of integers, the function returns the index of the element with the minimum value in the array. If there is more than one element with the minimum value, the returned index should be the smallest one.
  • If an empty array is passed to the function, it should raise an Exception.

Note: The arrays are indexed from .

Another co-worker has prepared functions that will perform the testing and validate returned results with expectations. Your task is to implement classes that will produce test data and the expected results for the testing functions. More specifically: function get_array() in TestDataEmptyArray class and functions get_array() and get_expected_result() in classes TestDataUniqueValues and TestDataExactlyTwoDifferentMinimums following the below specifications:

  • get_array() method in class TestDataEmptyArray has to return an empty array.
  • get_array() method in class TestDataUniqueValues has to return an array of size at least 2 with all unique elements, while method get_expected_result() of this class has to return the expected minimum value index for this array.
  • get_array() method in class TestDataExactlyTwoDifferentMinimums has to return an array where there are exactly two different minimum values, while method get_expected_result() of this class has to return the expected minimum value index for this array.
Solution:
static class TestDataEmptyArray {
    public static int[] get_array() {                        
        return new int[] {};
    }
}

static class TestDataUniqueValues {
    public static int[] get_array() {                        
        return new int[] {1, 2, 3, 4};
    }

    public static int get_expected_result() {           
        return 0;
    }
}

static class TestDataExactlyTwoDifferentMinimums {
    public static int[] get_array() {
        return new int[]{ 1, 2, 1 };
    }

    public static int get_expected_result() {
       return 0;
    }
}

Day 28 - RegEx, Patterns, and Intro to Databases

Consider a database table, Emails, which has the attributes First Name and Email ID. Given rows of data simulating the Emails table, print an alphabetically-ordered list of people whose email address ends in .

Solution:
class Contact {

	public String name;
	public String email;

	public Contact(String name, String email) {
		this.name = name;
		this.email = email;
	}
}

static final String PATTERN_GMAIL = "\\[email protected]$";

public static List<String> checkWithGmail(Contact[] contacts) {
	ArrayList<String> gmailContacts = new ArrayList<>();
	for (int i = 0; i < contacts.length; i++) {
		if(matchEmail(contacts[i].email))
			gmailContacts.add(contacts[i].name);
	}
	Collections.sort(gmailContacts);
    return gmailContacts;
}

private static boolean matchEmail(String email) {
	  return Pattern
			  .compile(PATTERN_GMAIL)
			  .matcher(email)
			  .find();
}

Day 29 - Bitwise AND

Given set . Find two integers, and (where ), from set such that the value of is the maximum possible and also less than a given integer, . In this case, represents the bitwise AND operator.

Solution:
public static int getMaximumPossible(int n, int k) {
	 if(((k-1)|k) > n && k%2==0)
	     return k-2;
	 return k-1;
}

Releases

No releases published

Packages

No packages published

Languages