Create a customized data structure which evaluates functions in O(1)
Create a customized data structure such that it has functions :-
All the functions should be of O(1)
Question Source : amazon interview questions
1) create a custom stack of type structure with two elements, (element, min_till_now)
2) implement the functions on this custom data type
5 inserted successfully 7 inserted successfully 3 inserted successfully min element :: 3 removed successfully 2 inserted successfully 9 inserted successfully Last element :: 9 0 inserted successfully min element :: 0 removed successfully 11 inserted successfully min element :: 2
Time complexity : Each function runs in O(1)
This article is contributed by Mandeep Singh. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.