Smallest Index With Equal Value
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem is about finding the smallest index i in an array nums where the value at t
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem is about finding the smallest index `i` in an array `nums` where the value at that index is equal to `i % 10`. This involves checking each element of the array to see if it meets the condition.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. **Initialization**: Start with the index `i` initialized to 0.\n2. **Iteration**: Use a `while` loop to iterate through the array from the beginning to the end.\n   - For each index `i`, check if the value at `nums[i]` is equal to `i % 10`.\n   - If the condition is met, return the index `i`.\n   - Otherwise, increment `i` and continue the loop.\n3. **Return**: If the loop completes without finding any such index, return `-1`.\n\n# Complexity\n- **Time complexity**: \n  - The time complexity is \\(O(n)\\), where \\(n\\) is the length of the array `nums`. This is because, in the worst case, we may need to check each element of the array once.\n  \n- **Space complexity**: \n  - The space complexity is \\(O(1)\\) because the algorithm uses a constant amount of extra space regardless of the input size.\n\n# Code\n\n```java\nclass Solution {\n    public int smallestEqual(int[] nums) {\n        int i = 0; // Initialize the index i to 0\n        while (i < nums.length) { // Loop through the array\n            if (nums[i] == i % 10) { // Check if the value at nums[i] equals i % 10\n                return i; // If condition is met, return the current index i\n            }\n            i++; // Increment the index\n        }\n        return -1; // If no such index is found, return -1\n    }\n}\n```\n\n# Example Walkthrough\n\nLet\'s go through an example to understand how this code works:\n\n**Example 1**:\n- Input: `nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]`\n- The loop checks each element:\n  - `nums[0] == 0 % 10` (true), so the function returns `0`.\n\n**Example 2**:\n- Input: `nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]`\n- The loop checks each element:\n  - `nums[0] == 0 % 10` (false)\n  - `nums[1] == 1 % 10` (true), so the function returns `1`.\n\nIn both examples, the function finds the smallest index that meets the condition or returns `-1` if no such index exists.
['Array', 'Java']