0% found this document useful (0 votes)
17 views

Debugging questions

The document outlines a debugging exercise involving two levels of tasks. Level 1 focuses on converting encrypted messages and binary codes into text, while Level 2 involves printing a matrix in spiral form and debugging provided code snippets in C++, Java, and Python. Each code snippet contains syntax, logical, and runtime errors that need to be corrected.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Debugging questions

The document outlines a debugging exercise involving two levels of tasks. Level 1 focuses on converting encrypted messages and binary codes into text, while Level 2 involves printing a matrix in spiral form and debugging provided code snippets in C++, Java, and Python. Each code snippet contains syntax, logical, and runtime errors that need to be corrected.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

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 = mat.size();

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 ;

2.Java:

java.util.ArrayList;

import java.util.List

public class Main {

public static List<Integer> print Spiral(int[][] mat) {

List<Integer> ans = new ArrayList<>();

int n = mat.length;

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++)

ans.add(mat[top][i]);

top++;

for (int i = top; i <= bottom; i++)

ans.add(mat[i][right]);

right--;

if (top <= bottom) {

for (int i = right; i <= left; i--)

ans.add(mat[bottom][i]);
bottom--;

if (left <= right) {

for (int i = bottom; i >= top; i--)

ans.add(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++){

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

while (top <= bottom and left >= right):

for i range(left, right + 1):

ans.append(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)

ans.append(mat[bottom][i])

bottom -= 1
if (left <= right):

for i in range(bottom,, -1):

ans.append(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)

You might also like