LESSON 35 / 75·2 min readFoundation

Arrays and strings in Java

Should knowConcept lesson
01 Understand02 Recall03 Prepare

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

java
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)

PAUSE & RECALL

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

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: Hashing and maps in Java

Adapted from 15_DSA_JAVA.md · “2. Arrays and strings in Java”. Examples are study fragments; framework behavior can depend on your version.