The keyboard have only 3 keys, K,L,A and performs 3 operations ctrl-A(select all), crtl-C(copy), ctrl-V(paste). Return the maximum number of KLA words that can be formed for a given N.
Asked in the Code-pair technical stage. The SQL version uses input rows and candidate operation sequences, where invalid candidates must be ignored.
Write a PostgreSQL query to return the maximum valid result for every requested input.
n and max_kla_words.0.n ascending.| Column | Type | Description |
|---|---|---|
| input_idPK | INT | Identifier for the input case |
| n | INT | Number of keyboard operations allowed |
| requested | BOOLEAN | Whether this input must appear in the output |
| Column | Type | Description |
|---|---|---|
| sequence_idPK | INT | Identifier for a candidate operation sequence |
| input_id | INT | Input case associated with the candidate |
| operation_sequence | VARCHAR(120) | Operations used by the candidate |
| kla_words | INT | Number of KLA words produced |
| is_valid | BOOLEAN | Whether the candidate is valid |