Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ParthBarot-BoTreeConsulting/d410b6ec0e65653dd0f4802c9f8fa601 to your computer and use it in GitHub Desktop.
Save ParthBarot-BoTreeConsulting/d410b6ec0e65653dd0f4802c9f8fa601 to your computer and use it in GitHub Desktop.
Programming test

Problem

Assuming there is an array A = [1,3,-1,4,2], We have the linked list built as following,

A[0] = 1
A[1] = 3
A[3] = 4
A[4] = 2
A[2] = -1

We have to ignore when the next poiner is -1, which means the linked list ends now. So, the length of this list is 4 as it ends on A[2]

Write an programm to calculate a length of the given array of length N where N could be between (1..200000) as per the above explanation.

You could choose Ruby/Python/Javascript for this.

Timelimit - 30-40 minutes

Problem

There is a table called events with columns types as following, we need to write a query sorted by source_id and event_type in ascending order with the latest value (by time).

Full table

source_id, event_type,   value, time
2 , 4,  63,   2017-06-21T12:30:00Z
2 , 2,  21,   2017-06-21T12:12:00Z
2 , 3,  -90,  2017-06-21T12:57:00Z
3 , 2,  26,   2017-06-21T12:42:00Z
2 , 2,  3,  2017-06-21T13:50:00Z

Expected output

source_id, event_type,  value,  time
2, 2, 3,   2017-06-21T13:50:00Z
2, 3, -90, 2017-06-21T12:57:00Z
2, 4, 63,  2017-06-21T12:30:00Z
3, 2, 26,  2017-06-21T12:42:00Z

First write down a query postgreSQL.

You can use the sqlfiddle created here by me (http://sqlfiddle.com/#!9/df831/1), and create your own fiddle and try querying for PostgreSQL

Timelimit - 30-40 minutes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment