## How to Return Random Values in Java

The challenge Ghost objects are instantiated without any arguments. Ghost objects are given a random color attribute of white” or “yellow” or “purple” or “red”… Read More »How to Return Random Values in Java

The challenge Ghost objects are instantiated without any arguments. Ghost objects are given a random color attribute of white” or “yellow” or “purple” or “red”… Read More »How to Return Random Values in Java

The challenge Compare two version numbers version1 and version2.If version1 > version2 return 1; if version1 < version2 return -1;otherwise return 0. You may assume that the version strings are non-empty and contain only digits and the . character. The . character does not… Read More »How to Compare Version Numbers in Java

The challenge Create a method take that accepts a list/array and a number n, and returns a list/array array of the first n elements from the list/array. If you need… Read More »How to Return the First N Elements in Java

The challenge Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row… Read More »How to Search a 2d Matrix/Array in Java

The challenge Write a function that returns the total surface area and volume of a box as an array: [area, volume] The solution in Java We… Read More »Calculate the Surface Area and Volume of a Box with Java

The challenge Complete the function which takes two arguments and returns all numbers which are divisible by the given divisor. First argument is an array… Read More »Find Numbers which are Divisible by given Number in Java

The challenge Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum result of ai XOR aj, where… Read More »Get the Maximum XOR of Two Numbers in an Array in Java

The challenge Given a number, find its opposite. Examples: The solution in Java We return the number itself multiplied by a negative 1. This can… Read More »How to Get the Opposite of a Number in Java

The challenge You are given the length and width of a 4-sided polygon. The polygon can either be a rectangle or a square.If it is a square, return its… Read More »How to Find the Area or Perimeter of a 4-sided Polygon using Java

The challenge We take in a String where the first place contains a number, write a function that takes in this String and returns an… Read More »How to Parse Int from Char in Java

The challenge Given a sorted (in ascending order) integer array nums of n elements and a target value, write a function to search target in nums. If target exists, then return its index, otherwise return -1. Example 1: Input:… Read More »How to Search a Binary Tree in Java

The challenge Given a linked list, rotate the list to the right by k places, where k is non-negative. Example 1: Input: 1->2->3->4->5->NULL, k = 2 Output: 4->5->1->2->3->NULL Explanation: rotate… Read More »How to Rotate a Singly Linked List in Java

The challenge You are given the root node of a binary search tree (BST) and a value to insert into the tree. Return the root node of the BST after… Read More »How to Insert into a Binary Search Tree using Java

The challenge Every non-negative integer N has a binary representation. For example, 5 can be represented as “101” in binary, 11 as “1011” in binary, and so on. Note that except for N = 0, there… Read More »Find the Complement of Base 10 Integer in Java

The challenge You have a RecentCounter class which counts the number of recent requests within a certain time frame. Implement the RecentCounter class: RecentCounter() Initializes the counter with zero recent… Read More »Solve the Number of Recent Calls Challenge in Java

The challenge Write a program that finds the summation of every number from 1 to num. The number will always be a positive integer greater… Read More »How to Calculate the Summation of a Number in Java

The challenge Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order.… Read More »How to Calculate all Unique Combinations of a Target using Backtracking in Java

The challenge Our football team finished the championship. The result of each match look like “x:y”. Results of all matches are recorded in the collection.… Read More »Calculate the Total Amount of Points using Java

The challenge Task Given three integers a ,b ,c, return the largest number obtained after inserting the following operators and brackets: +, *, () In other words , try every combination of a,b,c with [*+()] , and… Read More »Calculate the biggest of 3 numbers using Java

The challenge Consider an array/list of sheep where some sheep may be missing from their place. We need a function that counts the number of… Read More »How to Count an Array of Boolean Values in Java

The challenge You are driving a vehicle that has capacity empty seats initially available for passengers. The vehicle only drives east (ie. it cannot turn around and drive west.) Given a list… Read More »How to Solve the Car Pooling Challenge in Java

The challenge Write a function called repeat_str which repeats the given string src exactly count times. The solution in Java Java comes with a built-in on the String class. Called repeat,… Read More »How to Repeat a String in Java

The challenge Given an array of integers your solution should find the smallest integer. For example: Given [34, 15, 88, 2] your solution will return 2 Given [34, -345,… Read More »How to Find the Smallest Integer in the Array in Java

The challenge Given a number n, return the number of positive odd numbers below n, EASY! Expect large Inputs! Test cases The solution in Java At first… Read More »How to Count Odd Numbers Below N using Java

The challenge Given a string s consists of upper/lower-case alphabets and empty space characters ‘ ‘, return the length of last word (last word means the last appearing… Read More »How to get the Length of the Last Word in a String using Java