Before solving a database question on HackerRank, ensure that your environment is set up correctly. If you haven't taken the sample test, start by familiarizing yourself with the interface.
Environment Settings: Hover over icons in the top bar to see their functions. You can switch between light or dark mode, choose your editor emulation (e.g., Vim, Emacs), enable auto-complete, and select your preferred programming language.
Solving a Database Question
HackerRank database questions typically involve working with one or more tables, with schemas provided in the problem statement. The available database languages are:
- MS SQL Server
- MySQL
- PostgreSQL
- DB2
- Oracle
You can select your preferred language at the top of the editor window. All queries are executed on standard database servers running on the Ubuntu platform.
Producing the Required Output
Most challenges require you to produce output in a specific format and order. If the order of rows is not specified, they can appear in any order. Key points to remember:
- String Matching: Scoring is based solely on string matching. Ensure that your output precisely matches the required format, including spelling and numeric precision.
-
Formatting: Pay close attention to the required format. For example, ensure that numeric outputs match exactly, including trailing zeros (e.g.,
9.0
is not the same as9
).
Testing and Submitting Your Code
Once you’ve written your query, you can test it by pressing the Run Query button below the editor. This will execute your code against the provided tables.
When you're confident in your solution, press Submit to finalize your answer.
Answering Database Questions
Here is a quick video to get you started with the Answering Database programming questions workflow.
Or, if you prefer to follow directions, here are the steps for your ready reference.
Steps
- In your Test, select the Database Engineer question or click Solve.
- Read the problem statement carefully and refer to the given data schema, if any.
- In the code editor, choose the DB language. Only the permitted languages are displayed in this list. For example, if the test setter wants to assess your DB programming skills in SQL, you may see only the Microsoft SQL Server option available to answer the question.
- Write your query in the editor and click Run Query. Your answer is validated to return the expected output.
- Click Submit answer & continue to save your answer. You can revisit this question and change your submitted answer any number of times by clicking on Modify before the Test ends.
See the following topics for detailed information: