PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates proficiency in fundamental algorithmic problem-solving, specifically array manipulation, string processing, and the use of basic data structures along with performance and complexity reasoning.

  • Medium
  • Amazon
  • Coding & Algorithms
  • Data Scientist

Solve Algorithmic Challenges in Online Coding Assessments

Company: Amazon

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

##### Scenario Online assessment requiring implementation of common algorithmic problems. ##### Question Given an array of integers and a target, return indices of the two numbers that add up to the target (assume exactly one solution). 2) Given a string, determine the length of the longest substring without repeating characters. ##### Hints Use hash maps for O(n) solutions; mind edge cases like empty input.

Quick Answer: This question evaluates proficiency in fundamental algorithmic problem-solving, specifically array manipulation, string processing, and the use of basic data structures along with performance and complexity reasoning.

Two Sum

Given an array of integers `nums` and an integer `target`, return the indices of the two numbers such that they add up to `target`. You may assume that each input has exactly one solution, and you may not use the same element twice. Return the answer as a list of the two indices `[i, j]` with `i < j`. Example 1: Input: nums = [2, 7, 11, 15], target = 9 Output: [0, 1] (because nums[0] + nums[1] == 9) Example 2: Input: nums = [3, 2, 4], target = 6 Output: [1, 2] Use a hash map to achieve an O(n) single-pass solution.

Constraints

  • 2 <= len(nums) <= 10^4
  • -10^9 <= nums[i] <= 10^9
  • -10^9 <= target <= 10^9
  • Exactly one valid answer exists.

Examples

Input: ([2, 7, 11, 15], 9)

Expected Output: [0, 1]

Explanation: nums[0] + nums[1] = 2 + 7 = 9.

Input: ([3, 2, 4], 6)

Expected Output: [1, 2]

Explanation: nums[1] + nums[2] = 2 + 4 = 6; note nums[0]=3 alone cannot reuse itself.

Input: ([3, 3], 6)

Expected Output: [0, 1]

Explanation: Duplicate values; the two distinct indices 0 and 1 sum to 6.

Input: ([-1, -2, -3, -4, -5], -8)

Expected Output: [2, 4]

Explanation: Negatives: nums[2] + nums[4] = -3 + -5 = -8.

Input: ([0, 4, 3, 0], 0)

Expected Output: [0, 3]

Explanation: Two zeros at indices 0 and 3 sum to the target 0.

Hints

  1. A brute-force O(n^2) approach checks every pair, but you can do better.
  2. As you iterate, store each number's index in a hash map.
  3. For each number, check whether target - number is already in the map; if so you have your pair.

Longest Substring Without Repeating Characters

Given a string `s`, find the length of the longest substring that contains no repeating characters. A substring is a contiguous sequence of characters within the string. Example 1: Input: s = "abcabcbb" Output: 3 (the answer is "abc", with length 3) Example 2: Input: s = "bbbbb" Output: 1 (the answer is "b") Example 3: Input: s = "pwwkew" Output: 3 (the answer is "wke"; note "pwke" is a subsequence, not a substring) Use a sliding window with a hash map of last-seen indices for an O(n) solution.

Constraints

  • 0 <= len(s) <= 5 * 10^4
  • s consists of English letters, digits, symbols, and spaces.

Examples

Input: ("abcabcbb",)

Expected Output: 3

Explanation: The longest unique substring is "abc" with length 3.

Input: ("bbbbb",)

Expected Output: 1

Explanation: Every character repeats; the best window is a single "b".

Input: ("pwwkew",)

Expected Output: 3

Explanation: The longest unique substring is "wke" with length 3.

Input: ("",)

Expected Output: 0

Explanation: Empty string has no characters, so the answer is 0.

Input: ("abba",)

Expected Output: 2

Explanation: After the repeat 'b' then 'a', start must jump correctly; the best is "ab" or "ba" of length 2.

Input: ("dvdf",)

Expected Output: 3

Explanation: Tricky case: the answer is "vdf"; start must not move backward when 'd' repeats.

Input: (" ",)

Expected Output: 1

Explanation: A single space is one unique character, length 1.

Hints

  1. Maintain a sliding window [start, i] that always contains only unique characters.
  2. Track the most recent index where each character was seen in a hash map.
  3. When you encounter a repeat that lies inside the current window, jump start to one past its previous index.
Last updated: Jun 25, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Implement Top-p (Nucleus) Sampling in NumPy - Amazon (medium)
  • Implement Multi-Head Attention from Scratch in NumPy - Amazon (medium)
  • Detect and Break a Cycle in a Singly Linked List - Amazon (medium)
  • Caesar Cipher with Translation-Table Optimization - Amazon (medium)
  • Minimum Drone Delivery Time on a Ring of Hubs - Amazon (medium)