Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Max KLA Words with 3 Keys
00:00
5 left

Max KLA Words with 3 Keys

HardSQL · PostgreSQL

Problem

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.

Output

  1. One row per requested input N.
  2. Return n and max_kla_words.
  3. Include requested inputs without valid candidates with a value of 0.
  4. Sort by n ascending.

Schema

keyboard_inputs
ColumnTypeDescription
input_idPKINTIdentifier for the input case
nINTNumber of keyboard operations allowed
requestedBOOLEANWhether this input must appear in the output
candidate_sequences
ColumnTypeDescription
sequence_idPKINTIdentifier for a candidate operation sequence
input_idINTInput case associated with the candidate
operation_sequenceVARCHAR(120)Operations used by the candidate
kla_wordsINTNumber of KLA words produced
is_validBOOLEANWhether the candidate is valid
Tableskeyboard_inputscandidate_sequences
Interviewer

Your question is Max KLA Words with 3 Keys. Start with the requirements and the two tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.