-
Notifications
You must be signed in to change notification settings - Fork 382
Closed
Labels
Description
LeetCode Username
samleetcode76
Problem Number, Title, and Link
- Smallest Index With Digit Sum Equal to Index
Bug Category
Incorrect test case (Output of test case is incorrect as per the problem statement)
Bug Description
my code giving right answer but it is showing wrong .code give below
Language Used for Code
C++
Code used for Submit/Run operation
class Solution {
public:
int smallestIndex(vector<int>& nums) {
int n=nums.size();
unordered_map<int,int>mp;
for(int i=0;i<n;i++)
{
string s= to_string(nums[i]);
int x=s.size();
int sum=0;
for(int j=0;j<x;j++)
{
sum+=s[j]-'0';
}
mp[i]=sum;
}
for(auto &pair:mp)
{
if(pair.first==pair.second)
{
return pair.first;
}
}
return -1;
}
};Expected behavior
expecte output for test case nums =[1,10,11] is 1 ,my code also gives 1 but it is showing 2
Screenshots
No response
Additional context
No response