Top Wipro Coding Questions and Solutions

Wipro-Coding-Questions
Wipro-Coding-Questions

Table of Contents

Introduction

The coding assessment is one of the most important sections in Wipro on-campus and off-campus drives. Candidates are given two coding problems that must be solved within the stipulated time of 60 minutes. The assessments are of medium-level difficulty with one of the questions being easy and the other one being slightly trickier to solve. Generally, the cut-off requires candidates to solve at least one question but this may differ based on various circumstances.

You can choose to use C++, Java or Python and do not need to implement function signatures that have been provided by the editor. Functions must be used as provided in the problem, otherwise, this may lead to a failure during code compilation. You can include other libraries if needed and the signature might call other functions that have been defined by you. Now, let us cover some Wipro coding questions and their solutions.

Top 6 Wipro Coding Questions and Solutions

Here are the top 6 Wipro Coding Questions and their solutions:

Let us suppose that a person is given two numbers ‘A’ and ‘B’ as two arrays of ‘N’ and ‘M’ length respectively. All the array elements individually represent a digit. How will the person find the sum of the two numbers and how can the sum be returned in the form of an array?

Additional Notes, Input Formats, and Samples: Click here

Solution: (Java)

/*

        Time Complexity: O(max(N, M))

        Space Complexity: O(1)

        Where N is the size of the first array and M is the size of the second array.

 */

public class Solution {

public static int[] findArraySum(int[] a, int n, int[] b, int m) {

int ans[] = new int[Math.max(n, m)];

int carry = 0;

int sum = 0;

int k = ans.length – 1;

int i = n – 1;

        int j = m – 1;

while (i >= 0 || j >= 0) {

sum = 0;

            // If we have some elements left in the first array, then add it to the sum.

if (i >= 0) {

sum += a[i];

i–;

}

            // If we have some elements left in the second array, then add it to the sum.

if (j >= 0) {

sum += b[j];

j–;

}

sum += carry;

int lastDigit = sum % 10;

carry = sum / 10;

ans[k–] = lastDigit;

}

        // If still some carry is left, then push it to the answer.

if (carry != 0) {

int[] newAns = new int[ans.length + 1];

newAns[0] = carry;

for (int p = 1; p < newAns.length; p++) {

newAns[p] = ans[p – 1];

}

return newAns;

}

return ans;

}

}

How can one reverse any given number?

Additional Notes, Input Formats and Samples: Click here

Solution: (Java)

/*

Time Complexity: O(log N to the base 10)

Space Complexity: O(1)

Where N is the given input.

*/

public class Solution {

public static long reverseNumber(long n) {

// Remove all trailing zeros

while (n % 10 == 0) {

n = n / 10;

}

// Declare reverseNum and remainder and initialize them with 0

long reverseNum = 0;

long reminder = 0;

while (n > 0) {

reminder = (int) (n % 10);

reverseNum = reverseNum * 10 + reminder;

n = n / 10;

}

// Return the reverse number

return reverseNum;

}

}

Let’s assume two people are playing the game where they both get a set of ‘N’ distinct integers. They take turns to make a move where each can choose ‘X’ and ‘Y’ distinct integers from the sets in a way that the set does not end up containing the absolute difference which is X-Y. The player making the move currently then adds the integer X-Y to the set, making the size of the set grow by one. In the case where the current player cannot make a valid move, the player loses. Who will win the game, the player who goes first or the player who goes second?

Additional Notes, Input Formats and Samples: Click here

Solution: (Python)

“””

    Time Complexity : O(N * log(Max_Element) )

    Space Complexity : O(N)

    Where ‘N’ is size of initial set.

“””

# Function to find the gcd of two integers.

def gcd(a, b): 

    if (b == 0): 

        return a

    return gcd(b, a % b)

# Function to find the gcd of all the elements of an array.

def gcdCalc(ar, n):

    ans = ar[0]

    for i in range(1,n):

        ans = gcd(ar[i], ans)

    return ans

def gameWinner(arr, n) :

    n=len(arr)

    gcdVal = gcdCalc(arr, n)

    maxx = -1

    for i in range(n):

        if (arr[i] > maxx) :

            maxx = arr[i]

    # Total moves performed in game.

    movesLeft = maxx // gcdVal – n

    ans=str()

    # If total moves are odd , Alice wins.

    if (movesLeft % 2 != 0) :

        ans = “Alice”

    else :

        ans = “Bob”

    return ans

A person is given an array (‘arr’) of ‘N’ length. At every index, the array contains single digit elements. The person needs to return the total sum of all array elements while keeping the final sum a single digit as well. In order to return a single-digit output, the person needs to add the digits of the output till only a single digit remains. How will the person carry this out?

Additional Notes, Input Formats and Samples: Click here

Solution: (Python)

”’

    Time Complexity: O( N ).

    Space Complexity: O( 1 ).

    Where, N is the size of the array/list.

”’

def specialSum(arr, n):

    # Declare a variable ‘sum’ and initialize it with zero.

    summ = 0

    for i in range(n):

        # Add each element to the variable ‘sum’.

        summ += arr[i]

        if summ > 9:

            ”’

                Store the sum of the digits of the variable

                ‘sum’ in a new variable ‘tempSum’.

            ”’

            tempSum = 0

            tempSum += summ % 10

            summ = summ // 10

            tempSum += summ

            # Update ‘sum’ as ‘tempSum’.

            summ = tempSum

    return summ

Arrange a few characters in the ‘N’ number of rows where the first pattern is a left triangle and then the second pattern is a right triangle. Finally, there will be a pattern that will be the mirror image of the combined top half. THE integer ‘N’ will denote the given number of rows. Here, the pattern for N equals 3.

Additional Notes, Input Formats and Samples: Click here

Solution: (C++)

/*

    Time Complexity: O(N^2)

    Space Complexity: O(N^2)

    Where ‘N’ denotes the number of lines of the pattern

*/

vector < vector < char > > numberPattern(int n) {

  // Initializing matrix to store the pattern

  vector < vector < char > > ans(2 * n, vector < char > (2 * n, ‘ ‘));

  // Loop tp create upper part of the pattern

  for (int i = 0; i < n; i++) {

    for (int j = 0; j <= 2 * (n – 1); j++) {

      // Condition to print spaces

      if (i + j < 2 * (n – 1) && (i < j)) {

        continue;

      } else if ((i + j) % 2 != 0) {

        continue;

      }

      // Condition to print ‘*’

      else {

        ans[i][j] = ‘*’;

      }

    }

  }

  // Loop to create lower part of the pattern

  for (int i = n – 2; i > -1; i–) {

    for (int j = 0; j <= 2 * (n – 1); j++) {

      // Condition to print spaces

      if (j > i && (i + j) < 2 * (n – 1)) {

        continue;

      } else if ((i + j) % 2 != 0) {

        continue;

      }

      // Condition to print ‘*’

      else {

        ans[(2 * n) – i – 2][j] = ‘*’;

      }

    }

  }

  // Return the matrix

  return ans;

}

You are given a binary number as a string (‘S’), which is ‘N’ size. Convert this binary number into its integer decimal equivalent and then print it.

Notes, Input Formats and Samples: Click here

Solution: (C++)

/*

    Time Complexity: O(N)

    Space Complexity: O(1)

    Where N is the given size of the given string.

*/

#include<string>

#include<vector>

int convert(int N,string &str)

{

    //Declaring a variable for storing the decimal equivalent of binary number

    int value = 0;

    //Declaring a variable ‘baseVal’ for keeping track of the power of 2

    int baseVal = 1;

    for (int i = N – 1; i >= 0; i–)

    {

        if(str[i] == ‘1’)

        {

            value += baseVal;

        }

        baseVal *= 2;

    }

    return value;

}

Here are some more Wipro coding questions for practice:

Key Takeaways

Wipro is a great company, and many budding developers wish to join this massive Indian MNC. However, one must first clear the coding assessment section in order to progress to the HR interview. Thus, it is important to get enough practice to solve the Wipro coding questions with ease.