Skip to content

Java solutions to Daily Coding Problem questions for code interviews

Notifications You must be signed in to change notification settings

logreg-n-coffee/daily-coding-questions-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Daily Coding Problem & Solutions (Java)

This repository contains solutions to Daily Coding Problem questions in Java.

Installation

  • Clone the repository.
  • Run the following command
cd "path/to/file" && javac QuestionXX.java && java QuestionXX

Note: XX indicates the question number

Contributing

If you would like to contribute to the project, please follow these steps:

  • Fork the repository.
  • Create a new branch.
  • Make your changes and commit them.
  • Push to your forked repository.
  • Create a pull request.
  • Credits

License

This project is licensed under the MIT License. See the LICENSE file for more information.


List of Questions

  • Q 150: nearest k points from the central point
  • Q 151: replace the pixel and adjacent same colored pixels
  • Q 152: generate one of the numbers with its corresponding probability
  • Q 153: find the smallest distance between any two given words in a string
  • Q 154: implement a stack using only a heap
  • Q 155: find the majority element, which appears more than half the time
  • Q 156: smallest number of squared integers which sum to n
  • Q 157: given a string, determine whether any permutation of it is a palindrome
  • Q 158: given a matrix, Starting from the top left corner, find the number of ways to reach the bottom right corner
  • Q 159: given a string, return the first recurring character in it, or null if there is no recurring character
  • Q 160: given a tree where each edge has a weight, compute the length of the longest path in the tree
  • Q 161: given a 32-bit integer, return the number with its bits reversed
  • Q 162: given a list of words, return the shortest unique prefix of each word
  • Q 163: given an arithmetic expression in Reverse Polish Notation, write a program to evaluate it
  • Q 164: find a duplicate element in linear time and space
  • Q 165: given an array of integers, return a new array where each element in the new array is the number of smaller elements to the right of that element in the original input array
  • Q 166: implement a 2D iterator class
  • Q 167: given a list of words, find all pairs of unique indices such that the concatenation of the two words is a palindrome
  • Q 168: given an N by N matrix, rotate it by 90 degrees clockwise
  • Q 169: given a linked list, sort it in O(n log n) time and constant space
  • Q 170: find the shortest transformation sequence
  • Q 171: find the busiest time interval
  • Q 172: substring search for words
  • Q 173: Write a function to flatten a nested dictionary, namespace the keys with a period
  • Q 174: Explain ad-hoc polymorphism, parametric polymorphism, and subtype polymorphism
  • Q 175: Calculate Markov chain
  • Q 176: Check one-to-one character mapping for string 1 and string 2
  • Q 177: Rotate a linked list
  • Q 178: Probabilistic game simulation
  • Q 179: Reconstruct the binary search tree based on its postorder traversal
  • Q 180: Given a stack of N elements, interleave the first half of the stack
  • Q 181: Given a string, split it into as few strings as possible such that each string is a palindrome
  • Q 182: Given an undirected graph, check if the graph is minimally-connected
  • Q 183: Describe what happens when you type a URL into your browser and press Enter
  • Q 184: Given n numbers, find the greatest common denominator between them
  • Q 185: Given two rectangles on a 2D graph, return the area of their intersection
  • Q 186: Given an array of positive integers, divide the array into two subsets such that the difference between the sum of the subsets is as small as possible
  • Q 187: Given a list of rectangles. Compute whether a pair of rectangles overlap each other
  • Q 188: Fix Function Closure Bug
  • Q 189: Given an array of elements, return the length of the longest subarray where all its elements are distinct
  • Q 190: Given a circular array, compute its maximum subarray sum in O(n) time
  • Q 191: Given a collection of intervals, find the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping
  • Q 192: Given an array of non-negative integers, determine whether you can get to the end of the array
  • Q 193: Given a array of numbers representing the stock prices of a company in chronological order, write a function that calculates the maximum profit you could have made from buying and selling that stock
  • Q 194: Given two lists of n points, one list p1, p2, ..., pn on the line y = 0 and the other list q1, q2, ..., qn on the line y = 1. Write an algorithm to determine how many pairs of the line segments intersect
  • Q 195: Given i1, j1, i2, and j2, compute the number of elements of M smaller than M[i1, j1] and larger than M[i2, j2] in a given matrix
  • Q 196: Given the root of a binary tree, find the most frequent subtree sum
  • Q 197: Given an array and a number k that's smaller than the length of the array, rotate the array to the right k elements in-place.
  • Q 198: Given a set of distinct positive integers, find the largest subset such that every pair of elements in the subset (i, j) satisfies either i % j = 0 or j % i = 0
  • Q 199: Given a string of parentheses, find the balanced string that can be produced, from it using the minimum number of insertions and deletions
  • Q 200: Compute the smallest set of points that stabs X, a set of n intervals on the real line
  • Q 201: Given an array of arrays of integers, return the weight of the maximum weight path
  • Q 202: Write a program that checks whether an integer is a palindrome
  • Q 203: Find the minimum element in O(log N) time in an array sorted in ascending order is rotated at some pivot unknown to you beforehand
  • Q 204: Given a complete binary tree, count the number of nodes in faster than O(n) time
  • Q 205: Given an integer, find the next permutation of it in absolute order.
  • Q 206: Given an array and a permutation, apply the permutation to the array
  • Q 207: Given an undirected graph G, check whether it is bipartite
  • Q 208: Given a linked list of numbers and a pivot k, partition the linked list so that all nodes less than k come before nodes greater than or equal to k
  • Q 209: Write a program that computes the length of the longest common subsequence of three given strings
  • Q 210: Test the conjecture of Collatz sequence and find out the longest sequence with limit of n <= 1000000
  • Q 211: Given a string and a pattern, find the starting indices of all occurrences of the pattern in the string
  • Q 212: Given a column number, return its alphabetical column id in Excel Spreadsheets
  • Q 213: Given a string, return a list of allowed IP addresses
  • Q 214: Given an integer n, return the length of the longest consecutive run of 1s in its binary representation
  • Q 215: Given the root to a binary tree, return its bottom view
  • Q 216: Given a number in Roman numeral format, convert it to decimal
  • Q 217: Given input N, find the smallest sparse number greater than or equal to N
  • Q 218: Write an algorithm that computes the reversal of a directed graph
  • Q 219: Implement Connect Four
  • Q 220: You and an opponent take turns choosing either the first or last coin from the row, removing it from the row, and receiving the value of the coin. Write a program that returns the maximum amount of money you can win
  • Q 221: Create an algorithm to find the nth sevenish number
  • Q 222: Given an absolute pathname that may have . or .. as part of it, return the shortest standardized path
  • Q 223: Write a program to compute the in-order traversal of a binary tree using O(1) space
  • Q 224: Given a sorted array, find the smallest positive integer that is not the sum of a subset of the array
  • Q 225: Solve Josephus question
  • Q 226: You come across a dictionary of sorted words in a language you've never seen before. Write a program that returns the correct order of letters in this language
  • Q 227: Implement a Boggle Solver
  • Q 228: Given a list of numbers, create an algorithm that arranges them in order to form the largest possible integer
  • Q 229: Find smallest turns required to play Snakes and Ladders
  • Q 230: Solve egg dropping question
  • Q 231: Given a string with repeated characters, rearrange the string so that no two adjacent characters are the same. If this is not possible, return None
  • Q 232: Implement a PrefixMapSum class. insert(key: str, value: int) and sum(prefix: str)
  • Q 233: Implement the function fib(n), which returns the nth number in the Fibonacci sequence, using only O(1) space
  • Q 234: Given an undirected graph with weighted edges, compute the maximum weight spanning tree
  • Q 235: Given an array of numbers of length N, find both the minimum and maximum using less than 2 * (N - 2) comparisons
  • Q 236: Determine if a new point p lies inside a polygon defined in a list of N points
  • Q 237: Given a k-ary tree, determine whether it is symmetric
  • Q 238: Implement a blackjack solver that maximizes the player's score
  • Q 239: Find the possible unlock patterns of an Android lock screen given the length of the unlock pattern
  • Q 240: There are N couples sitting in a row of length 2 * N. They are currently ordered randomly, but would like to rearrange themselves so that each couple's partners can sit side by side
  • Q 241: Count the h-index of a researcher. A researcher has index h if at least h of her N papers have h citations each
  • Q 242: You are given an array of length 24, where each element represents the number of new subscribers during the corresponding hour. Implement a data structure to save the subscribers and has range query and point update functionalities
  • Q 243: Given an array of numbers N and an integer k, your task is to split N into k partitions such that the maximum sum of any partition is minimized. Return this sum
  • Q 244: Implement the algorithm of Sieve of Eratosthenes
  • Q 245: You are given an array of integers, where each element represents the maximum number of steps that can be jumped going forward from that element. Write a function to return the minimum number of jumps you must take in order to get from the start to the end of the array
  • Q 246: Given a list of words, determine whether the words can be chained to form a circle
  • Q 247: Given a binary tree, determine whether or not it is height-balanced
  • Q 248: Find the maximum of two numbers without using any if-else statements, branching, or direct comparisons
  • Q 249: Given an array of integers, find the maximum XOR of any two elements
  • Q 250: A cryptarithmetic puzzle is a mathematical game where the digits of some numbers are represented by letters. Each letter represents a unique digit
  • Q 251: Given an array of a million integers between zero and a billion, out of order, how can you efficiently sort it? Assume that you cannot store an array of a billion elements in memory
  • Q 252: Create an algorithm to turn an ordinary fraction a / b, where a < b, into an Egyptian fraction
  • Q 253: Given a string and a number of lines k, print the string in zigzag form
  • Q 254: Given a binary tree, convert it to a full one by removing nodes with only one child
  • Q 255: Given a graph, find its transitive closure
  • Q 256: Given a linked list, rearrange the node values such that they appear in alternating low -> high -> low -> high ... form
  • Q 257: Given an array of integers out of order, determine the bounds of the smallest window (indices) that must be sorted in order for the entire array to be sorted
  • Q 258: Given a binary tree, write an algorithm to print the nodes in boustrophedon order
  • Q 259: Given a dictionary of words, determine the letters the first player should start with, such that with optimal play they cannot lose
  • Q 260: Reconstruct an array following a +/- pattern
  • Q 261: Build a Huffman tree based on the frequency dictionary
  • Q 262: Find all the bridges in a graph
  • Q 263: Determine whether an input string is a valid pattern
  • Q 264: Create an algorithm that finds a De Bruijn sequence
  • Q 265: A company would like to give the smallest positive amount to each worker consistent with the constraint that if a developer has written more lines of code than their neighbor, they should receive more money. Given an array representing a line of seats of employees at MegaCorp, determine how much each one should get paid
  • Q 266: Given a dictionary of words and an input word, create a function that returns all valid step words
  • Q 267: Given an 8x8 matrix, determine whether the king is in check
  • Q 268: Given a 32-bit positive integer N, determine whether it is a power of four in faster than O(log N) time
  • Q 269: Given a string representing Domino forces, Determine the orientation of each tile after the dominoes stop falling
  • Q 270: Solve a graph problem to calculate the total amount of time needed for a message to spread from Node 0 to cover all nodes in the graph
  • Q 271: Given a sorted list of integers of length N, determine if an element x is in the list without performing any multiplication, division, or bit-shift operations
  • Q 272: Write a function, throw_dice(N, faces, total), that determines how many ways it is possible to throw N dice with some number of faces each to get a specific total
  • Q 273: Given a sorted array of distinct elements, return a fixed point (an element whose value is equal to its index), if one exists. Otherwise, return null
  • Q 274: Given a string consisting of parentheses, single digits, and positive and negative signs, convert the string into a mathematical expression to obtain the answer
  • Q 275: Given an integer N, print the Nth term of the Look and Say Sequence
  • Q 276: Implement an efficient string matching algorithm
  • Q 277: Write a program that takes in an array of integers representing byte values, and returns whether it is a valid UTF-8 encoding
  • Q 278: Given an integer N, construct all possible binary search trees with N nodes
  • Q 279: Each student can be placed in a friend group, which can be defined as the transitive closure of that student's friendship relations. In other words, this is the smallest set such that no student in the group has any friends outside this group. Find the number of the friend groups in total
  • Q 280: Given an undirected graph, determine if it contains a cycle
  • Q 281: Find common cumulative length of an array of array of numbers
  • Q 282: Given an array of integers, determine whether it contains a Pythagorean triplet
  • Q 283: Given an integer N, write a program that returns, in order, the first N regular numbers
  • Q 284: Given a binary tree and a particular node, find all cousins of that node
  • Q 285: You are given an array representing the heights of neighboring buildings on a city street, from east to west. The city assessor would like you to write an algorithm that returns how many of these buildings have a view of the setting sun, in order to properly value the street
  • Q 286: Solve the skyline of a city problem
  • Q 287: You are given a list of (website, user) pairs that represent users visiting websites. Come up with a program that identifies the top k pairs of websites with the greatest similarity.
  • Q 288: Write a function that returns how many steps are needed to find Kaprekar's contant for a given numbers
  • Q 289: Solve the Nim problem
  • Q 290: Solve the Quxes problem by determining the smallest number of them remaining after the transformation
  • Q 291: If at most two people can fit in a rescue boat, and the maximum weight limit for a given boat is k, determine how many boats will be needed to save everyone
  • Q 292: Solve the 2-coloring problem
  • Q 293: Shape a series of stones into a pyramid such that the height of each stone increases by one until reaching the tallest stone, after which the heights decrease by one. The start and end stones of the pyramid should each be one stone high.

Releases

No releases published

Packages

No packages published

Languages