Java Interview Cheat Sheet (Java 17+)
Goal: One consistent, modern syntax reference for Java, DSA & backend interviews. 1. Comparator Integer.compare(a,b); // ⭐ Ascending (avoid a-b overflow) Integer.compare(b,a); // ⭐ Descending a.
Search for a command to run...
Goal: One consistent, modern syntax reference for Java, DSA & backend interviews. 1. Comparator Integer.compare(a,b); // ⭐ Ascending (avoid a-b overflow) Integer.compare(b,a); // ⭐ Descending a.
Problem You are given an m x n integer matrix grid where each cell is either 0 (empty) or 1 (obstacle). You can move up, down, left, or right from and to an empty cell in one step. Return the minimum
Problem Given two arrays, val[] and wt[] , representing the values and weights of items, and an integer capacity representing the maximum weight a knapsack can hold, determine the maximum total value
Problem You are given an array nums consisting of non-negative integers. You are also given a queries array, where queries[i] = [x<sub>i</sub>, m<sub>i</sub>]. (link) The answer to the i<sup>th</sup> query is the maximum bitwise XOR value of x<sub>i<...
Problem Given an integer array nums, return the maximum result of nums[i] XOR nums[j], where 0 <= i <= j < n. (link) Example 1: Input: nums = [3,10,5,25,2,8] Output: 28 Explanation: The maximum result is 5 XOR 25 = 28. Example 2: Input: nums = [14,7...
Problem Given a string s consisting of lowercase English characters, determine the total number of distinct non-empty substrings present in the string. A substring is defined as a contiguous block of characters within the string. Two substrings are c...
Problem Given an array of strings words[], find the longest string such that every prefix of it is also present in words[]. If multiple strings have the same maximum length, return the lexicographically smallest one. (link) If no such string is found...
Problem Ninja has to implement a data structure ”TRIE” from scratch. Ninja has to complete some functions. 1) Trie(): Ninja has to initialize the object of this “TRIE” data structure. 2) insert(“WORD”): Ninja has to insert the string “WORD” into th...
Problem A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker. (link) Imp...