Debugging
Level 1:
Convert the given encrypted messages into decrypted messages.
Convert the given binary code into text.
1. 01001001 01110100
2. 01001000 01101001
3. 1001000 01100101 01101100 01101100 01101111
Convert the given numbers into text.
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:
Printing the given matrix in spiral form.
Example:Input: Matrix[][] = { { 1, 2, 3, 4 },
{ 5, 6, 7, 8 },
{ 9, 10, 11, 12 },
{ 13, 14, 15, 16 } }
Outhput: 1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9, 5, 6, 7, 11, 10.
Q. Codes for this topic is given containg syntax,logical and runtime errors
in c++,Java and python. You task is to choose any language and debug the
code and get the correct output.
1.C++:
#include<bits/stdc++.h>
using namespace std
vector<int> print Spiral(vector<vector<int>> mat) {
vector<int> ans;
int n = [Link]();
int m = mat[0].size();
int top = 0, left = 0, bottom = n - 1 right = m - 1;
while (top <= bottom & left <= right) {
for (int i = left; i <= right; i++) {
ans.push_back(mat[top][i]); }
top+;
for (int i = top; i <= bottom; i++) {
ans.push_back(mat[i][right]); }
right--;
if (top <= bottom) {
for (int i = right; i <= left; i--) {
ans.push_back(mat[bottom][i]); }
bottom--;
if (left <= right) {
for (int i = bottom; i >= top; i--) {
ans.push_back(mat[i][left]); }
left++;
return ans;
int main() {
vector<vector<int>> mat {{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12},
{13, 14, 15, 16};
vector<int> ans = printSpiral(mat);
for(int i = 0;;i++){
cout<<ans[i]<" ";
}
cout<<endl;
return ;
[Link]:
[Link];
import [Link]
public class Main {
public static List<Integer> print Spiral(int[][] mat) {
List<Integer> ans = new ArrayList<>();
int n = [Link];
int m = mat[0].length;
int top = 0, left = 0, bottom = n - 1right = m - 1;
while (top <= bottom & left <= right){
for (int i = left; i <= right; i++)
[Link](mat[top][i]);
top++;
for (int i = top; i <= bottom; i++)
[Link](mat[i][right]);
right--;
if (top <= bottom) {
for (int i = right; i <= left; i--)
[Link](mat[bottom][i]);
bottom--;
if (left <= right) {
for (int i = bottom; i >= top; i--)
[Link](mat[i][left]);
left++;
return ans;
public static void main(String[] args) {
int[][] mat = {{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12},
{13, 14, 15, 16};
List<Integer> ans = printSpiral(mat);
for(int i = 0;;i++){
[Link]([Link](i) + " );
[Link]();
}
3. Python:
def printSpiral(mat):
ans = []
n = len(mat)
m = len(mat[0])
top = 0
left = 0
bottom = n - 1
right = m - 1
while (top <= bottom and left >= right):
for i range(left, right + 1):
[Link](mat[top][i])
top += 1
for i in range(top, bottom + 1):
ansappend(mat[i][right])
right -= 1
if (top <= bottom):
for i in range(right, left - 1, -1)
[Link](mat[bottom][i])
bottom -= 1
if (left <= right):
for i in range(bottom,, -1):
[Link](mat[i][left])
left = 1
return ans
mat = [[1, 2, 3, 4],
[5, 6, 7, 8]
[9, 10, 11, 12],
[13, 14, 15, 16]
ans = Print Spiral(mat)
print(ans)