Solving Hackerrank problem and getting error index out of bound.
This is a C# coding. The problem statement can be found here https://www.hackerrank.com/challenges/append-and-delete/problem
class Solution {
// Complete the appendAndDelete function below.
static string appendAndDelete(string s, string t, int k) {
int counter = 0;
int n = s.Length;
int m = t.Length;
for(int i = 0; i <= Math.Min(n,m); i++)
{
if (s[i] == t[i])
{
counter++;
}
else
{
break;
}
}
int a = n - counter;
int b = m - counter;
if (a + b <= k){
return "Yes";
}
else{
return "No";
}
}
Upon executing I am getting this error
[ERROR] FATAL UNHANDLED EXCEPTION: System.IndexOutOfRangeException: Index was outside the bounds of the array. at Solution.appendAndDelete (System.String s, System.String t, System.Int32 k) [0x0001b] in solution.cs:24 at Solution.Main (System.String[] args) [0x0002c] in solution.cs:53
The indices seem to be in range need help on this.