Jetpack Compose Auto-Scrolling List with a Start/Stop Toggle and Hex Color Switching
Company: Robinhood
Role: Android Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Technical Screen
Build an Android screen in Jetpack Compose that displays a list which scrolls automatically. The screen has two one-tap controls: one turns automatic scrolling on and off, and the other changes the color of the list items. Item colors are provided as hex color strings (for example, `"#1E88E5"`), so your code must convert a hex string into a Compose `Color` instead of using built-in `Color` constants.
### Constraints and Clarifications
- The list content is not the focus. Any simple items, such as labelled rows, are acceptable unless the interviewer supplies data.
- The prompt does not fix the scroll speed, what happens at the end of the list, or which colors are available. Ask, then state the behavior you implement.
- The color input is a string, not a numeric literal or a color resource. Decide which hex formats you accept and what happens when a string is malformed.
- Write working Compose code and be ready to explain how state flows between the controls, the list, and any background work.
### Clarifying Questions
- Should the list move smoothly at a constant speed, or advance one item at a time?
- At the last item, should scrolling stop, jump back to the top, or appear to loop forever?
- If the user drags the list during auto-scroll, should auto-scroll pause, and should it resume by itself?
- Does the color control cycle through a fixed palette of hex strings, apply a new color to every item, or color items individually? Where do the hex strings come from?
- Which formats must be accepted: `#RRGGBB`, `#AARRGGBB`, lowercase digits, strings without the leading `#`?
- Should the on/off state and the selected color survive a configuration change such as rotation?
### Part 1 — Auto-Scrolling List with a Start/Stop Control
Show the items in a lazy list and make the list scroll by itself while auto-scroll is on. One tap on a control starts auto-scroll when it is off and stops it when it is on. Stopping must halt the motion right away, and starting again must continue from the current position rather than resetting.
```hint Tie the loop to state
Look for the Compose side-effect API that starts a coroutine when a state value changes and cancels it automatically when that value changes again or the screen leaves composition.
```
#### What This Part Should Cover
- Where the on/off state lives and how both the control and the scrolling logic read it.
- How the list is scrolled programmatically, and how that work starts and is cancelled.
- Behavior at the end of the list and when the user touches the list during auto-scroll.
- Smooth, frame-rate-independent motion without blocking the main thread.
### Part 2 — One-Tap Item Color Change from Hex Strings
Add a second control that changes the item color with one tap. The colors are supplied as hex strings, and you must convert each one into a Compose `Color`. Explain which API or parsing logic you use, which formats it accepts, and how invalid strings are handled.
```hint Check the channel order
Work out where the alpha channel sits in an eight-digit hex string on this platform, and what alpha a six-digit string should end up with.
```
#### What This Part Should Cover
- A correct conversion from a hex string to `Color`, including the alpha channel.
- Validation and a defined fallback for malformed input.
- How the selected color is stored and applied to items, and where parsing happens relative to composition.
### What a Strong Answer Covers
- Clear state ownership for the auto-scroll flag and the selected color, including behavior across configuration changes.
- A scrolling loop whose lifetime is bound to state and composition, with no leaked or duplicated work after repeated taps.
- Hex parsing that is correct, defensive, and testable without a device.
- Explicit choices for the unspecified behaviors: end of list, user drags, and invalid colors.
- A plan for testing both the scrolling behavior and the parser.
### Follow-up Questions
1. How would you make the list appear to loop forever, and what does that change about item keys and the initial scroll position?
2. How would you write a UI test proving that auto-scroll actually stops after the second tap?
3. How would the design change if the hex palette came from a server response that may contain invalid entries?
4. How would you accommodate users who find automatically moving content distracting or uncomfortable?
Overview: Build an Android screen in Jetpack Compose with a list that scrolls by itself, a one-tap control that starts and stops the motion, and a one-tap control that recolors list items using colors parsed from hex strings. It tests Compose state, coroutine side effects, lazy list scrolling, and robust hex color parsing.