Amazon Interview Question
Data ScientistsCountry: United States
Lets say there are three items . so
1.Take these three items in hashmap/dictionary(python)
2.Put unsold=1
3.Traverse through the hashmap and if the item is sold put unsold as 0
4.Repeat 3 for all the items
5.Once all the items been marked as unsold/sold traverse through the hashmap and find an entry with unsold stilll equal to 1.
6.The item is 5 is unsold so can be printed.
- Let's say we have 100 Product , so we can make bool array of 100 elements
bool arr[100];
int item;
- next we add sold item first
for (int i = 0 ; i < 100 ; ++i)
{
cin >> item;
arr[item] = 1;
}
- then we make another loop printing
for (int i = 0 ; i < 100 ; ++i)
{
if (arr[i] == 0) cout << "item number" << i+1<<"is not sold";
}
Algo O(n)
I would probe before answering this question first
- hprem991 June 21, 20161> What kinda database (dynamo or RDBMS)
2> What does unsold item mean? It it depend on the unaltered quantity of items after listing for a certain duration of days?
Having asked that, any approach can gives me this solution but thinking in worst case scenario, I would say.
1> Take snapshot of each database.
2> For each category,
For each item in the category
{if item.quantity(listedDate) == item.quaniity(currentDate)}
{{list.add(item) // item as unsold }}
// Algo runs over O(n) for n numbers of items