Arrays and strings in Java
Key operations
- index access:
arr[i] - length:
arr.length - loops:
for,while - string manipulation:
substring,charAt,split,equals
Common Java questions
- Two Sum
- Best Time to Buy and Sell Stock
- Maximum Subarray
- Move Zeroes
- Product of Array Except Self
- Longest Substring Without Repeating Characters
- Valid Palindrome
- Group Anagrams
Java example: two sum
import java.util.*;
class Solution {
public int[] twoSum(int[] nums, int target) {
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < nums.length; i++) {
int needed = target - nums[i];
if (map.containsKey(needed)) {
return new int[] { map.get(needed), i };
}
map.put(nums[i], i);
}
return new int[] {};
}
}Time and space complexity
- Time: O(n)
- Space: O(n)
Can you explain it without the notes?
Arrays and strings in Java
Use your own words. Explain an example and one limitation before checking the explanation.
Check your explanation
Key operations
Turn this concept into a clear answer.
Practice this conceptAdapted from 15_DSA_JAVA.md · “2. Arrays and strings in Java”. Examples are study fragments; framework behavior can depend on your version.