Debugging questions
Debugging questions
Level 1:
1. 01001001 01110100
2. 01001000 01101001
1. 20-8-9-19-9-19-13-5
2. 3-15-13-16-21-20-5-18-19-3-9-5-14-3-5
3. 72-101-108-108-111-32-119-111-114-108-100
Level 2:
Example:Input: Matrix[][] = { { 1, 2, 3, 4 },
{ 5, 6, 7, 8 },
{ 9, 10, 11, 12 },
1.C++:
#include<bits/stdc++.h>
vector<int> ans;
int n = mat.size();
int m = mat[0].size();
ans.push_back(mat[top][i]); }
top+;
right--;
ans.push_back(mat[bottom][i]); }
bottom--;
ans.push_back(mat[i][left]); }
left++;
return ans;
int main() {
{5, 6, 7, 8},
for(int i = 0;;i++){
cout<<ans[i]<" ";
}
cout<<endl;
return ;
2.Java:
java.util.ArrayList;
import java.util.List
int n = mat.length;
int m = mat[0].length;
ans.add(mat[top][i]);
top++;
ans.add(mat[i][right]);
right--;
ans.add(mat[bottom][i]);
bottom--;
ans.add(mat[i][left]);
left++;
return ans;
{5, 6, 7, 8},
for(int i = 0;;i++){
System.out.print(ans.get(i) + " );
System.outprintln();
}
3. Python:
def printSpiral(mat):
ans = []
n = len(mat)
m = len(mat[0])
top = 0
left = 0
bottom = n - 1
right = m - 1
ans.append(mat[top][i])
top += 1
ansappend(mat[i][right])
right -= 1
ans.append(mat[bottom][i])
bottom -= 1
if (left <= right):
ans.append(mat[i][left])
left = 1
return ans
[5, 6, 7, 8]
print(ans)