# Android Technical Interview Question!

Here's a mock interview question that pushes MVVM to its technical limits!&#x20;

This question is meant to be completed (comfortably) within a **60-minute timeslot**.&#x20;

Most companies will allow you to ask (rather extensive) questions to your interviewer AND use internet searches (minus Generative AI) to complete this task.&#x20;

{% hint style="warning" %}
As a disclaimer, this is an Android question specifically for **Jetpack Compose**. Jetpack Compose is industry standard, but older / more sluggish companies may have Android Native questions. Android Native is an outdated framework we do not teach in this course.
{% endhint %}

{% hint style="info" %}
This app heavily tests understanding of **state management**. You may also encounter questions about Networking, Concurrency, UI building, etc., but those are not tested in this question.
{% endhint %}

Ready for your question? Here's your task!

***

### The Infinite Entropy Row

{% hint style="info" %}
This has NO release code. Simply solve this from an empty activity.
{% endhint %}

This is a simple, one-screen (not-very-actually-useful) app that tests difficult use of state management / MVVM by having you implement an infinitely scrolling row of items that each have some remembered state!

In general, you'll try to match this UI:

<div data-full-width="false"><figure><img src="/files/hRpCC5QJFph5wX6nSUqB" alt="" width="188"><figcaption><p>UI Screen!</p></figcaption></figure></div>

First, watch this demo video to see what you'll aim to build:

{% file src="/files/GjnRRB0I9dbp29o0mPLU" %}
Solution Demo!
{% endfile %}

***

### Requirements

Here's a detailed breakdown of your requirements!

<details>

<summary>Entropy Counter</summary>

At the top of the screen, you'll see a counter for the current "Entropy" value within the app.&#x20;

*Entropy is a fancy math term for "randomness."*

You'll also see a little text for the most recently-spawned entropy value.

For now:

1. Make a large text for the current entropy value!
2. Make a smaller text that says something like "Recent Value: XXX"

In general, try to match our screenshot for UI (but that's not important).

</details>

<details>

<summary>The Infinite Row</summary>

Under the entropy counter, you'll build the infinite scrolling row!&#x20;

Here are some requirements specifying this row:

1. It scrolls infinitely! You shouldn't be able to realistically hit the end of the scroll.
2. Each entry in the row is a simple UI element that basically just displays a text. You can add a shape/surface to make it look pretty.
3. Scrolling on a new entry in the row should "spawn a new entropy value," and place it in the row entry as a simple text.
   1. This should be reflected in the "Recent Value" text.
   2. Spawning an entropy value means selecting a random value +- 100 around the entropy value (e.g. if the entropy value is 1000, it should select from 900 to 1100). Don't worry about inclusive/exclusive.
   3. Scrolling BACK on old entries should **NOT** overwrite their previous value. They should remember their sampled value.
4. Every time you scroll on a new entry, the entropy value should increase by **1000**.
   1. This should be reflected in the "Entropy' text.

</details>

<details>

<summary>Many Infinite Rows (Challenge!)</summary>

Can you make several infinite rows that have separate contents and scrolls?&#x20;

They should all sample values from the same entropy value, and contribute to the same total entropy.

</details>

***

### Tips

* You \*can\* solve this with MVVM (and I recommend it! State management is so much easier with MVVM). But you can also just solve it with mutable states.
  * If you DO solve it with MVVM, don't bother setting up Hilt or whatever. You can just make mock VMs as regular objects, or `ViewModel`s. (Not Hilt).
* You don't necessarily need to follow best practices by, for example, making different files for each Composable, to save time.
* Ignore how in the demo, if I scroll too fast, N/As appear. You can assume we'll scroll at a reasonable speed.

### HINTS:

<details>

<summary>(Expand for hints!)</summary>

* Using `items(Int.MAX_VALUE)` within a LazyColumn will render a ton of of items in the row, with little performance cost due to how LazyColumn "recycles" views.
* `Random.nextInt(X, Y)` chooses a random integer in the value range.&#x20;
* Use `LaunchedEffect(Unit) {}` to determine when a view is scrolled on. Then, have some `onRender()` viewModel function that takes in the item index to determine if it's been initialized yet.
* You can represent each list with a FINITE `List<Int>` , where non-existent indices indicate that the user hasn't scrolled on those indexes yet. When the scroll occurs, you then can add to the list to indicate the entropy value on those items.
  * To make multiple rows, you can consider using a `List<List<Int>>` where each `List<Int>` represents one row.

</details>

***

### Solution!

See the `.zip` solution below! There's even a bit too much polish to this; you can be scrappier if needed!

{% file src="/files/pMHTC4m2BEijqWJpwBi6" %}
Solution code!
{% endfile %}

Was that tough? It probably should have been. This is a very difficult state management question; if you can master this you'll have mastered this cornerstone of Compose!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://android-course.cornellappdev.com/archive/spring-2025-course-material/bonus-week-or-android-job-search/android-technical-interview-question.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
