Design a Compose one-to-five-star rating form with review text, derived button validation, and confirmed submission UI. Explain state ownership, duplicate-click protection, error recovery, accessibility, and draft restoration.
Build a Compose Rating Form with Validated Submission State
Company: OpenAI
Role: Android Engineer
Category: Software Engineering Fundamentals
Difficulty: hard
Interview Round: Technical Screen
Design an Android Compose rating form. The user chooses one to five stars, enters a written review, and presses Submit. The button is enabled only after both a rating and review have been provided. After a successful submission, show a different UI confirming that the review was submitted.
### Constraints & Assumptions
- Rating values are integers from one through five.
- Clarify whether whitespace-only text counts as a review; this practice solution treats it as missing.
- Do not show successful submission merely because a network request started.
- Define loading, failure, and repeated-click behavior.
### Clarifying Questions to Ask
- Should the draft survive screen recreation or process recreation?
- Can the user edit while submission is in progress?
- What validation and duplicate-submission guarantees does the server provide?
```hint
The enabled state can be derived from form state; it does not need a separate mutable Boolean that can drift out of sync.
```
### What a Strong Answer Covers
Model rating, text, submission progress, errors, and confirmed completion in one coherent state flow. Explain state hoisting, event callbacks, derived validation, asynchronous submission, and accessible star selection.
### Follow-up Questions
- What happens if the request fails after the user taps Submit?
- How do you prevent a recomposition from submitting again?
- How would you restore the draft after recreation?
Overview: Design a Compose one-to-five-star rating form with review text, derived button validation, and confirmed submission UI. Explain state ownership, duplicate-click protection, error recovery, accessibility, and draft restoration.
Design an Android Compose rating form. The user chooses one to five stars, enters a written review, and presses Submit. The button is enabled only after both a rating and review have been provided. After a successful submission, show a different UI confirming that the review was submitted.
Constraints & Assumptions
Rating values are integers from one through five.
Clarify whether whitespace-only text counts as a review; this practice solution treats it as missing.
Do not show successful submission merely because a network request started.
Define loading, failure, and repeated-click behavior.
Clarifying Questions to Ask Guidance
Should the draft survive screen recreation or process recreation?
Can the user edit while submission is in progress?
What validation and duplicate-submission guarantees does the server provide?
What a Strong Answer Covers Guidance
Model rating, text, submission progress, errors, and confirmed completion in one coherent state flow. Explain state hoisting, event callbacks, derived validation, asynchronous submission, and accessible star selection.
Follow-up Questions Guidance
What happens if the request fails after the user taps Submit?
How do you prevent a recomposition from submitting again?