βββ README.md /README.md: -------------------------------------------------------------------------------- 1 | # π Company-Wise iOS Technical Interview Questions 2 | 3 |
4 | Prepared By: Shobhakar Tiwari 5 |
6 | 7 | - π Welcome, Iβm Shobhakar Tiwari working in the USA πΊπΈ and currently in the Central Standard Time Zone (CST). I enjoy writing blogs on Medium, contributing to the iOS dev community, and sharing iOS interview questions to support junior and senior iOS developers alike. 8 | 9 | - [If you preparing for iOS Interview feel free to connect for mentorship.](https://www.linkedin.com/in/shobhakar-tiwari/) 10 | 11 | - A comprehensive collection of real-world technical interview questions and scenarios from leading technology companies. This repository helps developers prepare for coding rounds, system design interviews, and technical assessments. 12 | 13 | ## **Walmart Mock Interview Question** 14 | - [Walmart Interview Question](#walmart-interview-question) 15 | - [Problem Statement](#problem-statement) 16 | - [Technical Requirements](#technical-requirements) 17 | - [Implementation Guide](#implementation-guide) 18 | - [Code Solution](#code-solution) 19 | - [Technical Deep Dive](#technical-deep-dive) 20 | 21 | ### Problem Statement 22 | **Real-time ETA Tracking in Ride-Sharing Application** 23 | 24 | Design and implement a feature for a ride-sharing application that displays real-time ETA (Estimated Time of Arrival) updates for drivers. The system must efficiently handle periodic network requests while maintaining optimal resource usage and user experience. 25 | 26 | ### Technical Requirements 27 | 1. Implement periodic ETA fetching (10-second intervals) 28 | 2. Handle view lifecycle management 29 | 3. Implement proper network request management 30 | 4. Ensure thread-safe UI updates 31 | 5. Implement memory leak prevention 32 | 6. Handle error cases and network failures 33 | 34 | ### Implementation Guide 35 | 36 | #### Architecture Components 37 | - **Timer System**: Manages periodic network requests 38 | - **Network Layer**: Handles API communication 39 | - **UI Layer**: Updates and manages view state 40 | - **Error Handling**: Implements retry mechanism with exponential backoff 41 | 42 | #### Key Considerations 43 | - Resource optimization during screen transitions 44 | - Thread safety in UI updates 45 | - Memory management 46 | - Network failure resilience 47 | 48 | ### Code Solution 49 | 50 | ```swift 51 | import UIKit 52 | 53 | class ETAViewController: UIViewController { 54 | // MARK: - Properties 55 | private var timer: Timer? 56 | private let etaURL = URL(string: "https://api.example.com/driver/eta")! 57 | 58 | // MARK: - Lifecycle Methods 59 | override func viewWillAppear(_ animated: Bool) { 60 | super.viewWillAppear(animated) 61 | startFetchingETA() 62 | } 63 | 64 | override func viewWillDisappear(_ animated: Bool) { 65 | super.viewWillDisappear(animated) 66 | stopFetchingETA() 67 | } 68 | 69 | // MARK: - Private Methods 70 | private func startFetchingETA() { 71 | timer = Timer.scheduledTimer( 72 | timeInterval: 10.0, 73 | target: self, 74 | selector: #selector(fetchETA), 75 | userInfo: nil, 76 | repeats: true 77 | ) 78 | timer?.fire() 79 | } 80 | 81 | private func stopFetchingETA() { 82 | timer?.invalidate() 83 | timer = nil 84 | } 85 | 86 | @objc private func fetchETA() { 87 | let task = URLSession.shared.dataTask(with: etaURL) { [weak self] data, response, error in 88 | guard let self = self else { return } 89 | 90 | if let error = error { 91 | print("Failed to fetch ETA: \(error)") 92 | return 93 | } 94 | 95 | guard let data = data else { return } 96 | if let eta = self.parseETA(from: data) { 97 | DispatchQueue.main.async { 98 | self.updateUI(with: eta) 99 | } 100 | } 101 | } 102 | task.resume() 103 | } 104 | 105 | private func parseETA(from data: Data) -> String? { 106 | return String(data: data, encoding: .utf8) 107 | } 108 | 109 | private func updateUI(with eta: String) { 110 | print("ETA Updated: \(eta)") 111 | } 112 | } 113 | ``` 114 | 115 | ### Technical Deep Dive 116 | 117 | #### 1. Network Failure Handling 118 | Implement an exponential backoff strategy for handling network failures: 119 | 120 | ```swift 121 | private func retryRequest(after delay: TimeInterval) { 122 | DispatchQueue.main.asyncAfter(deadline: .now() + delay) { [weak self] in 123 | self?.fetchETA() 124 | } 125 | } 126 | ``` 127 | 128 | #### 2. Thread Safety Implementation 129 | Ensure UI updates occur on the main thread: 130 | 131 | ```swift 132 | DispatchQueue.main.async { 133 | self.updateUI(with: eta) 134 | } 135 | ``` 136 | 137 | #### 3. Request Cancellation 138 | Implement proper request cancellation to prevent resource leaks: 139 | 140 | ```swift 141 | private var currentTask: URLSessionDataTask? 142 | 143 | @objc private func fetchETA() { 144 | currentTask?.cancel() 145 | currentTask = URLSession.shared.dataTask(with: etaURL) { [weak self] data, response, error in 146 | // Handle response 147 | } 148 | currentTask?.resume() 149 | } 150 | ``` 151 | 152 | ## Contributing 153 | We welcome contributions! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change. 154 | 155 | ## All rights @Shobhakar Tiwari 156 | --------------------------------------------------------------------------------