Skip to content

A collection of Java interview practice problems and solutions

Notifications You must be signed in to change notification settings

tziporaziegler/Practice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Practice

A collection of Java interview practice problems and solutions, along with JUnit test files.

Table of Contents

Problems and Solutions

Data Structures

Array

  • Find the Smallest Number
    Given an array, find the smallest number in the array.
  • Find Missing Numbers
    In an array, 1-100 numbers are stored. One number is missing. How do you find it?
  • Find Duplicate Numbers
    In an array of 1-100, exactly one number is duplicate. How do you find it?
  • Compare Arrays
    Given two arrays, find which number(s) is not present in the second array.
  • Longest Consecutive Sequence
    Given an unsorted array of integers, find the length of the longest consecutive elements sequence.
  • Two Sum
    Given an array of integers, return indices of the two numbers such that they add up to a specific target.
  • Remove Duplicates from Sorted Array
    Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.
  • Pascal Triangle
    Given an integer x, generate the first x number of rows of Pascal’s triangle.
  • Powerset
    Given an array or set of objects, return a set of all possible subsets.

String

  • Remove Character
    Remove all instances of a specific character from the given String.
  • String Palindrome Check
    Given a String, check if the String is a valid palindrome.
  • Multiply String
    Given two numbers represented as strings, return multiplication of the numbers as a string. Do not use BigInteger.
  • Merge and Order String Characters
    Given an array of strings, return a single string containing all the characters in alphabetical order.

Stack

  • Array Implementation
    Includes the following methods: push(), pop(), peek(), size(), isEmpty() and isFull().
  • Balanced Parentheses
    Given a String, determine if the parentheses have pairs and are in order.

Linked List

Tree

  • Binary Tree
    Includes methods for inserting, removing, traversing (in order, pre-order, post-order)
    and searching (find by value, smallest, nth smallest element).

Algorithms

Sort

Search

Math

  • Is Prime
    Given an integer, determine whether the integer is a prime number.
  • Fibonacci Sequence
    Given an integer x, print x number of elements in the sequence.
    Given an integer, return the value of the element in that position of the sequence.
  • Integer Palindrome Check
    Given an integer, determine whether the integer is a valid palindrome.
  • Prime Sum
    Given an even number (greater than 2), return two prime numbers whose sum will be equal to given number.
  • Find Factors
    Return a list of all factors of a given integer.

Contributing

Know a better solution for one of these problems?
Have an alternate or more efficient solution that you think is worth including?
See a test case that wasn't accounted for?
See a way to improve an existing solution?

Contributions and code improvement suggestions are welcome! Simply submit a pull-request or create an issue.

Before suggesting improvements or new solutions, please check the test folder for JUnit tests that corrospond to the file you are editing, and make sure your code passes those test. The test folder structure follows the same structure as the src folder.