Deliveroo Interview Question | Data Structure | iOS SSE Interview
ฝัง
- เผยแพร่เมื่อ 28 ก.ย. 2024
- Filter items of dictionary based on array to create a menu for restaurant.
let menuItems: [String: Double] = ["Burger": 5.99, "Pizza": 8.99, "Pasta": 7.49, "Salad": 4.99, "Soda": 1.99]
let selectedItems: [String] = ["Burger", "Pizza", "Soda"]
Thanks for sharing such interview questions. Please continue to share such videos, we are getting educate from you.
The output part you talked about at the end is wrong. In Swift, we always have an unordered dictionary which is output1 in your case. Try running your program more than once and you can see the change in the output. The output preserved in the same order in your video is just a coincidence.
Hii, I seen your video what I did not understand How data structure managed in this. Please explain more.
let output1 = Dictionary(uniqueKeysWithValues: selectedItems.compactMap { key in menuItems[key].map { (key, $0) }})