PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This multi-part prompt evaluates string manipulation, hash map usage for grouping and lookup, and simulation of sequential commands, along with robustness in handling edge cases and explicit reasoning about time and space complexity.

  • medium
  • Goldman Sachs
  • Coding & Algorithms
  • Software Engineer

Solve string and hashmap coding tasks

Company: Goldman Sachs

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You will solve the following coding tasks (independent of each other). Provide clear input/output behavior and handle edge cases. ## 1) Longest non-repeating substring (length + substring) Given a string `s`, find: - The **maximum length** of a substring with **no repeated characters**. - **One** such substring achieving that maximum length. Return `(max_len, substring)`. **Clarifications / edge cases to handle:** - `s` can be empty. - If multiple substrings have the same max length, you may return any one (or specify a tie-break rule such as the leftmost). ## 2) Group strings by anagram Given an array of strings `strs`, group the strings into lists where each list contains strings that are anagrams of each other. Return the groups in any order. **Follow-up:** - State and justify the time and space complexity of your approach. ## 3) Execute grid moves from a command string (case-insensitive) You are on an infinite 2D grid starting at `(0, 0)`. You receive a command string `cmd` consisting of characters representing moves: - `U`/`u`: move up `(x, y+1)` - `D`/`d`: move down `(x, y-1)` - `L`/`l`: move left `(x-1, y)` - `R`/`r`: move right `(x+1, y)` Process the string in order and return the final coordinate `(x, y)`. **Clarifications:** - Commands should be treated **case-insensitively** (mixed upper/lower case may appear). - Define what you do with any invalid character (e.g., ignore it or raise an error).

Quick Answer: This multi-part prompt evaluates string manipulation, hash map usage for grouping and lookup, and simulation of sequential commands, along with robustness in handling edge cases and explicit reasoning about time and space complexity.

Part 1: Longest Non-Repeating Substring

Given a string s, find the maximum length of any contiguous substring that contains no repeated characters, and return one substring achieving that length. If multiple substrings have the same maximum length, return the leftmost one. If s is empty, return length 0 and the empty string.

Constraints

  • 0 <= len(s) <= 100000
  • s may contain any characters supported by Python strings.
  • A substring must be contiguous.
  • If there is a tie, return the leftmost maximum-length substring.

Examples

Input: ('abcabcbb',)

Expected Output: (3, 'abc')

Explanation: The longest substrings without repeated characters have length 3; the leftmost is 'abc'.

Input: ('bbbbb',)

Expected Output: (1, 'b')

Explanation: Every valid non-repeating substring has length 1.

Input: ('',)

Expected Output: (0, '')

Explanation: The empty string has no non-empty substrings.

Input: ('pwwkew',)

Expected Output: (3, 'wke')

Explanation: 'wke' is the leftmost longest substring with no repeated characters.

Input: ('abba',)

Expected Output: (2, 'ab')

Explanation: Both 'ab' and 'ba' have length 2, and the leftmost is 'ab'.

Hints

  1. Use a sliding window whose left boundary only moves forward.
  2. Track the most recent index where each character appeared.

Part 2: Group Strings by Anagram

Given an array of strings strs, group strings that are anagrams of each other. Two strings are anagrams if they contain exactly the same characters with the same frequencies, possibly in a different order. Treat characters case-sensitively. For deterministic output, return groups in the order their anagram class first appears in the input, and keep strings inside each group in their original input order.

Constraints

  • 0 <= len(strs) <= 10000
  • 0 <= len(strs[i]) <= 100
  • The total number of characters across all strings is at most 100000.
  • Anagram comparison is case-sensitive.

Examples

Input: (['eat', 'tea', 'tan', 'ate', 'nat', 'bat'],)

Expected Output: [['eat', 'tea', 'ate'], ['tan', 'nat'], ['bat']]

Explanation: 'eat', 'tea', and 'ate' share the same sorted signature; 'tan' and 'nat' share another.

Input: ([],)

Expected Output: []

Explanation: No strings means no groups.

Input: ([''],)

Expected Output: [['']]

Explanation: The empty string forms its own anagram group.

Input: (['', 'b', ''],)

Expected Output: [['', ''], ['b']]

Explanation: Both empty strings are anagrams and preserve their input order.

Input: (['ab', 'ba', 'abc', 'bca', 'cab', 'z'],)

Expected Output: [['ab', 'ba'], ['abc', 'bca', 'cab'], ['z']]

Explanation: Groups are returned by the first time each anagram signature appears.

Hints

  1. All anagrams become identical if their characters are sorted.
  2. Use a hashmap from an anagram signature to the list of words with that signature.

Part 3: Execute Case-Insensitive Grid Moves

You are on an infinite 2D grid starting at coordinate (0, 0). Given a command string cmd, process its characters from left to right. U or u moves up by increasing y by 1, D or d moves down by decreasing y by 1, L or l moves left by decreasing x by 1, and R or r moves right by increasing x by 1. Commands are case-insensitive. Invalid characters are ignored.

Constraints

  • 0 <= len(cmd) <= 100000
  • cmd may contain upper-case letters, lower-case letters, and invalid characters.
  • Invalid characters are ignored.
  • The grid is infinite, so coordinates may be negative.

Examples

Input: ('UDLR',)

Expected Output: (0, 0)

Explanation: The up/down and left/right moves cancel out.

Input: ('uRdl',)

Expected Output: (0, 0)

Explanation: Commands are case-insensitive, and these moves also cancel out.

Input: ('',)

Expected Output: (0, 0)

Explanation: With no commands, the position remains the origin.

Input: ('UUrrD',)

Expected Output: (2, 1)

Explanation: Two up moves, two right moves, and one down move end at (2, 1).

Input: ('U?xR lD',)

Expected Output: (0, 0)

Explanation: Invalid characters '?', 'x', and the space are ignored; valid moves are U, R, l, D.

Hints

  1. Normalize each command character to one case before checking it.
  2. Maintain two counters, x and y, and update them as you scan the string once.
Last updated: Jun 18, 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 an Integer Hash Map - Goldman Sachs
  • Implement a String Deque - Goldman Sachs (easy)
  • Find first non-repeating character index - Goldman Sachs (nan)
  • Solve string and hashmap interview tasks - Goldman Sachs (medium)
  • Count segments and optimize 3-server assignment - Goldman Sachs (medium)