Amazon Interview Question
Backend DevelopersCountry: United States
There are two choices to move the records whenever someone dragdrops (start:end) records. We could move (start:end) to after newIndex or we could move (end+1:newIndex) to before start. So,
if (end-start + 1 < newIndex - end) {
Move (start:end) to after newindex
} else {
Move (end+1:newIndex) to before start
}
Complexity: O(min(end-start + 1, newIndex - end))
Implement the equivalent of a linked list in the database with an MVC architecture.
e.g If you are using an RDBMS like AWS' RDS, then a tuple could be represented by (item ID, Next item ID). The primary key would be the item ID.
Whatever the new order of items is by the user could be sent to a web service through the from the UI client. The server side would then run through the list by running updates on the corresponding RDS entries.
Well, this involves shifting elements. Now, we have two choices: either move (start:end) indexes to newIndex or move (end+1:newIndex) to before start. While performing operations, we can decide which one is more efficient.
- Anonymous July 01, 2018Complexity would be O(min(end - start + 1, newIndex - end))