Category: Array coding problemNothing is here to trick you and we all use the internet to search / find answers, so develop as if you were doing it as part of normal day. As you...Input: Array Output: Printed output
codingMediumgraph#1
1. [Graph] — Shortest Path in Nutritional Database
Background: Nourish Care needs an efficient way to retrieve nutritional information and related food items based on shortest path heuristics in a database. This is critical for ensuring that users find related meal options easily, especially in a healthcare context. Problem statement: Given a graph represented as an adjacency list where nodes are food items, and weights are the distances metric (caloric difference), implement a function that returns the shortest path from a starting food item to a target food item. You should implement the following function:
2. Binary Search — Finding a user's nutritional data
Background: Nourish Care manages nutritional plans and records for users. Quickly searching through the nutritional data is essential for providing prompt support and personalized recommendations. Problem statement: Given a sorted array of n integers representing user IDs and a target user ID, implement a function to search for the target user ID using the binary search algorithm. Return the index of the target if found, or -1 if not found. Function/class signature:
Example 1: Input: users = [1, 3, 5, 7, 9], target = 5 Output: 2 Explanation: User ID 5 is located at index 2.Example 2: Input: users = [10, 20, 30, 40], target = 25 Output: -1 Explanation: User ID 25 does not exist in the list.Constraints:
1 <= n <= 10^5
Array is sorted in ascending order.
User IDs are unique.
codingMediumhash map#3
3. Hash Map — Count Unique Nutrients from Ingredients
Background: Nourish Care is focused on providing personalized nutrition solutions. To achieve this, they need to analyze various ingredients to determine their unique nutrient contributions. Problem statement: Given a list of ingredients where each ingredient is a string, and each string may contain multiple nutrients separated by commas (e.g., "Protein, Fiber, Vitamin C"), your task is to return a list of unique nutrients. The order of nutrients in the output list should reflect their first occurrence in the input list. Function/class signature:
Explanation: Iron and Calcium are unique, with Iron appearing first.
Constraints:
1 <= len(ingredients) <= 1000
Each ingredient string has 1 to 100 characters.
Nutrients in each ingredient are separated by a comma, and there may be leading or trailing spaces.
codingMediumhash map#4
4. HASH MAP — Find Unique User IDs
Background: At Nourish Care, handling user data efficiently is crucial for providing personalized care services. User IDs must be unique to ensure accurate tracking of patient records across the platform. Problem statement: You are given a list of user_ids representing users who have logged into the system. Some users may have logged in multiple times with different IDs due to system errors. Your task is to return a list of unique user IDs in the order they first appeared in the input list. Function/class signature:
Explanation: All IDs appear once except 'userA' which is limited to the first occurrence.
Constraints:
1 <= user_ids.length <= 1000
user_ids[i] is a string of alphanumeric characters, length in range [1, 20]
codingMediumgraph#5
5. [Graph] — Find the Optimal Nutritional Path
Background: Nourish Care aims to provide personalized nutritional plans for users, relying on their dietary preferences and nutritional needs. A critical challenge is optimizing meal recommendations based on user-defined criteria, which can be visualized as a graph of available meal options and their nutritional values. Problem statement: Given a set of meals where each meal can be connected to others in the graph with varying nutritional scores, implement a function that determines the optimal nutritional path from a starting meal to the target meal, maximizing the total nutritional score. The function should return the maximum nutritional score achievable along the path. Function/class signature: