Get free ebooK with 50 must do coding Question for Product Based Companies solved
Fill the details & get ebook over email
Thank You!
We have sent the Ebook on 50 Must Do Coding Questions for Product Based Companies Solved over your email. All the best!

Wipro Coding Questions And Answers

Last Updated on February 20, 2023 by Prepbytes

In general, coding questions in a Wipro interview might focus on evaluating the candidate’s ability to write clean, efficient, and well-organized code, as well as their problem-solving skills and understanding of programming principles. The coding questions might range from simple exercises to more complex problems that require the candidate to write algorithms or data structures from scratch. It is also possible that the candidate might be asked to solve real-world programming problems based on specific scenarios or requirements.

Wipro Coding Questions

Here are commonly asked coding questions in Wipro Company:

Question 1) Program for factorial of a number

Input

7

Answer:

// C++ program for factorial of a number
#include <iostream>
using namespace std;

unsigned int factorial(unsigned int n)
{
    int res = 1, i;
    for (i = 2; i <= n; i++)
        res *= i;
    return res;
}

// Driver code
int main()
{
    int num = 7;
    cout << "Factorial of "
        << num << " is "
        << factorial(num) << endl;
    return 0;
}

def factorial(n):
    
    res = 1
    
    for i in range(2, n+1):
        res *= i
    return res


num = 7;
print("Factorial of", num, "is",
factorial(num))

Output

Factorial of 7 is 120

Question 2) Find Second largest element in an array

Input

{4,7,19,17,11}

Answer:

#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main() {

    vector<int>v{4,7,19,17,11};
    set<int>s(v.begin(),v.end());
    v.clear();
    for(auto it:s)v.push_back(it);

    int n=v.size();
    
    cout<<"The Second Largest Element in Vector is: ";
    cout<<v[n-2]<<endl;
    return 0;
}
# your code goes here



v = [4, 7, 19, 17, 11]

s = set(v)

s = sorted(s)

print("The Second Largest Element in Vector is: ",s[-2])


Output

The Second Largest Element in Vector is: 17

Question 3) Check if the sum of digits of N is palindrome

Input

92

Answer:


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int num = 92;
    int sum = 0;

    while (num != 0) {
        int temp = (num % 10);
        sum = sum + temp;
        num /= 10;
    }


    string str = to_string(sum);

    string string_rev = "" + str;
    reverse(string_rev.begin(), string_rev.end());

    cout << ((str == string_rev) ? "Yes" : "No");
}


# code
num = int(92)
sum = int(0)

while num != 0:
    temp = int(num % 10)
    sum = sum+temp
    num = num/10

# convert sum to string
string = str(sum)

# reverse the string
string_rev = string[:: -1]

# check the palindrome
if string == string_rev:
    print("Yes")
else:
    print("No")


Output

Yes

Question 4) Pythagorean Triplet in an array

Input

{10, 4, 6, 12, 5}

Answer:

#include <iostream>

using namespace std;

// Returns true if there is Pythagorean triplet in ar[0..n-1]
bool isTriplet(int ar[], int n)
{
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                // Calculate square of array elements
                int x = ar[i] * ar[i], y = ar[j] * ar[j], z = ar[k] * ar[k];

                if (x == y + z || y == x + z || z == x + y)
                    return true;
            }
        }
    }

    // If we reach here, no triplet found
    return false;
}


int main()
{
    int ar[] = { 10, 4, 6,12, 5 };
    int ar_size = sizeof(ar) / sizeof(ar[0]);
    isTriplet(ar, ar_size) ? cout << "Yes" : cout << "No";
    return 0;
}
def isTriplet(ar, n):
    # Square all the elements
    for i in range(n):
        ar[i] = ar[i] * ar[i]

    # sort array elements
    ar.sort()

    # fix one element
    # and find other two
    # i goes from n - 1 to 2
    for i in range(n-1, 1, -1):
        # start two index variables from
        # two corners of the array and
        # move them toward each other
        j = 0
        k = i - 1
        while (j < k):
            # A triplet found
            if (ar[j] + ar[k] == ar[i]):
                return True
            else:
                if (ar[j] + ar[k] < ar[i]):
                    j = j + 1
                else:
                    k = k - 1
    # If we reach here, then no triplet found
    return False

# Driver program to test above function */
ar = [10, 4, 6, 12,5]
ar_size = len(ar)
if(isTriplet(ar, ar_size)):
    print("Yes")
else:
    print("No")

# This code is contributed by Aditi Sharma

Output

Yes

Question 5) Check whether two Strings are anagram of each other

Input

“gram”
“arm”

Answer:

// C++ program to check whether two strings are anagrams
// of each other
#include <bits/stdc++.h>
using namespace std;

/* function to check whether two strings are anagram of
each other */
bool areAnagram(string str1, string str2)
{
    // Get lengths of both strings
    int n1 = str1.length();
    int n2 = str2.length();

    // If length of both strings is not same, then they
    // cannot be anagram
    if (n1 != n2)
        return false;

    // Sort both the strings
    sort(str1.begin(), str1.end());
    sort(str2.begin(), str2.end());

    // Compare sorted strings
    for (int i = 0; i < n1; i++)
        if (str1[i] != str2[i])
            return false;

    return true;
}

// Driver code
int main()
{
    string str1 = "gram";
    string str2 = "arm";

    // Function Call
    if (areAnagram(str1, str2))
        cout << "The two strings are anagram of each other";
    else
        cout << "The two strings are not anagram of each "
                "other";

    return 0;
}
# your code goes here

class Solution:

    # Function is to check whether two strings are anagram of each other or not.
    def isAnagram(self, a, b):

        if sorted(a) == sorted(b):
            return True
        else:
            return False

# {
# Driver Code Starts

if __name__ == '__main__':
    a = "gram"
    b = "arm"
    if(Solution().isAnagram(a, b)):
        print("The two strings are anagram of each other")
    else:
        print("The two strings are not anagram of each other")

Output

The two strings are not anagram of each other

Question 6) Position of rightmost set bit

Input

19

Answer:

// C++ program for Position
// of rightmost set bit
#include <iostream>
#include <math.h>
using namespace std;

class prepbytes{

public:
    unsigned int getFirstSetBitPos(int n)
    {
        return log2(n & -n) + 1;
    }
};

// Driver code
int main()
{
    prepbytes p;
    int n = 19;
    cout << p.getFirstSetBitPos(n);
    return 0;
}

import math


def getFirstSetBitPos(n):

    return math.log2(n & -n)+1

# driver code


n = 19
print(int(getFirstSetBitPos(n)))


Output

1

Question 7) Remove all characters other than alphabets from string

Input

“pr*e;p..by, t’e^s?”

Answer:

#include <bits/stdc++.h>
using namespace std;


void removeSpecialchar(string s)
{
    int j = 0;
    for (int i = 0; i < s.size(); i++) {
        
        // Store only valid characters
        if ((s[i] >= 'A' && s[i] <= 'Z') ||
            (s[i] >='a' && s[i] <= 'z'))
        {
            s[j] = s[i];
            j++;
        }
    }
    cout << s.substr(0, j);
}

// driver code
int main()
{
    string s = "pr*e;p..by, t’e^s?";
    removeSpecialchar(s);
    return 0;
}
def removeSpecialCharacter(s):
    t = ""
    for i in s:
        if(i.isalpha()):
            t+=i
    print(t)
s = "pr*e;p..by, t’e^s?"
removeSpecialCharacter(s)

Output

prepbytes

Question 8) Count set bits in an integer

Input

13

Answer:

#include <bits/stdc++.h>
using namespace std;

int countSetBits(int n)
{
    // base case
    if (n == 0)
        return 0;
    else
        // if last bit set add 1 else add 0
        return (n & 1) + countSetBits(n >> 1);
}

// driver code
int main()
{
    int n = 13;
    // function calling
    cout << countSetBits(n);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int countSetBits(int n)
{
    // base case
    if (n == 0)
        return 0;
    else
        // if last bit set add 1 else add 0
        return (n & 1) + countSetBits(n >> 1);
}

// driver code
int main()
{
    int n = 13;
    // function calling
    cout << countSetBits(n);
    return 0;
}

# Python3 implementation of recursive
# approach to find the number of set
# bits in binary representation of
# positive integer n

def countSetBits( n):
    
    # base case
    if (n == 0):
        return 0

    else:

        # if last bit set add 1 else
        # add 0
        return (n & 1) + countSetBits(n >> 1)
        
# Get value from user
n = 13

# Function calling
print( countSetBits(n))	
        

Output

3

Question 9) Find Majority Element in an array which appears more than n/2 times.(n is size of array)

Input

{6,4,7,6,6,6,6,9}

Answer:

#include <bits/stdc++.h>
using namespace std;


void findMajority(int arr[], int n)
{
    int maxCount = 0;
    int index = -1; // sentinels
    for (int i = 0; i < n; i++) {
        int count = 0;
        for (int j = 0; j < n; j++) {
            if (arr[i] == arr[j])
                count++;
        }

    
        if (count > maxCount) {
            maxCount = count;
            index = i;
        }
    }

    
    if (maxCount > n / 2)
        cout << arr[index] << endl;

    else
        cout << "No Majority Element" << endl;
}


int main()
{
    int arr[] = { 6,4,7,6,6,6,6,9};
    int n = sizeof(arr) / sizeof(arr[0]);

    // Function calling
    findMajority(arr, n);

    return 0;
}
def findMajority(arr, n):

    maxCount = 0
    index = -1 
    for i in range(n):

        count = 1

        for j in range(i+1, n):

            if(arr[i] == arr[j]):
                count += 1

        # update maxCount if count of
        # current element is greater
        if(count > maxCount):

            maxCount = count
            index = i

    # if maxCount is greater than n/2
    # return the corresponding element
    if (maxCount > n//2):
        print(arr[index])

    else:
        print("No Majority Element")


# Driver code
if __name__ == "__main__":
    arr = [6,4,7,6,6,6,6,9]
    n = len(arr)

    # Function calling
    findMajority(arr, n)

def findMajority(arr, n):

    maxCount = 0
    index = -1 
    for i in range(n):

        count = 1

        for j in range(i+1, n):

            if(arr[i] == arr[j]):
                count += 1

        # update maxCount if count of
        # current element is greater
        if(count > maxCount):

            maxCount = count
            index = i

    # if maxCount is greater than n/2
    # return the corresponding element
    if (maxCount > n//2):
        print(arr[index])

    else:
        print("No Majority Element")


# Driver code
if __name__ == "__main__":
    arr = [6,4,7,6,6,6,6,9]
    n = len(arr)

    # Function calling
    findMajority(arr, n)

Output

6

Question 10) Program to validate an IP address

Input

ip1 = "222.111.111.111"
ip2 = "5555..555"
ip3 = "0000.0000.0000.0000"
ip4 = "1.1.1.1"

Answer:

// Program to check if a given
// string is valid IPv4 address or not
#include <bits/stdc++.h>
using namespace std;
#define DELIM "."

/* function to check whether the
string passed is valid or not */
bool valid_part(char* s)
{
    int n = strlen(s);
    
    // if length of passed string is
    // more than 3 then it is not valid
    if (n > 3)
        return false;
    
    // check if the string only contains digits
    // if not then return false
    for (int i = 0; i < n; i++)
        if ((s[i] >= '0' && s[i] <= '9') == false)
            return false;
    string str(s);
    
    // if the string is "00" or "001" or
    // "05" etc then it is not valid
    if (str.find('0') == 0 && n > 1)
        return false;
    stringstream geek(str);
    int x;
    geek >> x;
    
    // the string is valid if the number
    // generated is between 0 to 255
    return (x >= 0 && x <= 255);
}

/* return 1 if IP string is
valid, else return 0 */
int is_valid_ip(char* ip_str)
{
    // if empty string then return false
    if (ip_str == NULL)
        return 0;
    int i, num, dots = 0;
    int len = strlen(ip_str);
    int count = 0;
    
    // the number dots in the original
    // string should be 3
    // for it to be valid
    for (int i = 0; i < len; i++)
        if (ip_str[i] == '.')
            count++;
    if (count != 3)
        return false;
    
    // See following link for strtok()

    char *ptr = strtok(ip_str, DELIM);
    if (ptr == NULL)
        return 0;

    while (ptr) {

        /* after parsing string, it must be valid */
        if (valid_part(ptr))
        {
            /* parse remaining string */
            ptr = strtok(NULL, ".");
            if (ptr != NULL)
                ++dots;
        }
        else
            return 0;
    }

    
    if (dots != 3)
        return 0;
    return 1;
}

// Driver code
int main()
{

    
            
    char ip1[] = "222.111.111.111";
    char ip2[] = "5555..555";
    char ip3[] = "0000.0000.0000.0000";
    char ip4[] = "1.1.1.1";

    is_valid_ip(ip1) ? cout<<"Valid\n" : cout<<"Not valid\n";
    is_valid_ip(ip2) ? cout<<"Valid\n" : cout<<"Not valid\n";
    is_valid_ip(ip3) ? cout<<"Valid\n" : cout<<"Not valid\n";
    is_valid_ip(ip4) ? cout<<"Valid\n" : cout<<"Not valid\n";
    return 0;
}
# your code goes here


def in_range(n): #check if every split is in range 0-255
    if n >= 0 and n<=255:
        return True
    return False
    
def has_leading_zero(n): # check if every split has leading zero or not.
    if len(n)>1:
        if n[0] == "0":
            return True
    return False
def isValid(s):
    
    s = s.split(".")
    if len(s) != 4: #if number of splitting element is not 4 it is not a valid ip address
        return 0
    for n in s:
        
        if has_leading_zero(n):
            return 0
        if len(n) == 0:
            return 0
        try: #if int(n) is not an integer it raises an error
            n = int(n)

            if not in_range(n):
                return 0
        except:
            return 0
    return 1
        

if __name__=="__main__":
    
    
    ip1 = "222.111.111.111"
    ip2 = "5555..555"
    ip3 = "0000.0000.0000.0000"
    ip4 = "1.1.1.1"
    print(isValid(ip1))
    print(isValid(ip2))
    print(isValid(ip3))
    print(isValid(ip4))

    

Output

Valid
Not valid
Not valid
Valid

Question 11) Maximum profit by buying and selling a share at most k times

Input

3

[100, 30, 15, 10, 8, 25, 80]

Answer:

#include <climits>
#include <iostream>
using namespace std;


int maxProfit(int price[], int n, int k)
{

    int profit[k + 1][n + 1];

    // For day 0, you can't earn money
    // irrespective of how many times you trade
    for (int i = 0; i <= k; i++)
        profit[i][0] = 0;

    // profit is 0 if we don't do any transaction
    // (i.e. k =0)
    for (int j = 0; j <= n; j++)
        profit[0][j] = 0;

    // fill the table in bottom-up fashion
    for (int i = 1; i <= k; i++) {
        for (int j = 1; j < n; j++) {
            int max_so_far = INT_MIN;

            for (int m = 0; m < j; m++)
                max_so_far = max(max_so_far,
                                price[j] - price[m] + profit[i - 1][m]);

            profit[i][j] = max(profit[i][j - 1], max_so_far);
        }
    }

    return profit[k][n - 1];
}

// Driver code
int main()
{
    int k = 3;
    int price[] ={ 100, 30, 15, 10, 8, 25, 80};
    int n = sizeof(price) / sizeof(price[0]);

    cout << "Maximum profit is: "
        << maxProfit(price, n, k);

    return 0;
}
def maxProfit(prices, n, k):
    
    # Bottom-up DP approach
    profit = [[0 for i in range(k + 1)]
                for j in range(n)]
    
    # Profit is zero for the first
    # day and for zero transactions
    for i in range(1, n):
        
        for j in range(1, k + 1):
            max_so_far = 0
            
            for l in range(i):
                max_so_far = max(max_so_far, prices[i] -
                            prices[l] + profit[l][j - 1])
                            
            profit[i][j] = max(profit[i - 1][j], max_so_far)
    
    return profit[n - 1][k]

# Driver code
k = 3
prices = [100, 30, 15, 10, 8, 25, 80]
n = len(prices)

print("Maximum profit is:",
    maxProfit(prices, n, k))


Output

Maximum profit is: 72

Question 12) Number of subarrays having product less than K

Input

100

[1, 9, 2, 8, 6, 4, 3] 

Answer:

#include <iostream>
using namespace std;

int countsubarray(int array[], int n, int k)
{
    int count = 0;
    int i, j, mul;

    for (i = 0; i < n; i++) {
        // Counter for single element
        if (array[i] < k)
            count++;

        mul = array[i];

        for (j = i + 1; j < n; j++) {
            // Multiple subarray
            mul = mul * array[j];
        
            if (mul < k)
                count++;
            else
                break;
        }
    }

    return count;
}

// Driver Code
int main()
{
    int array[] = {1, 9, 2, 8, 6, 4, 3};
    int k = 100;
    int size = sizeof(array) / sizeof(array[0]);
    int count = countsubarray(array, size, k);
    cout << count << "\n";
}



def countsubarray(array, n, k):
    count = 0
    for i in range(0, n):

        # Counter for single element
        if array[i] < k:
            count += 1

        mul = array[i]

        for j in range(i + 1, n):

            # Multiple subarray
            mul = mul * array[j]

    
            if mul < k:
                count += 1
            else:
                break
    return count


# Driver Code
array = [1, 9, 2, 8, 6, 4, 3]
k = 100
size = len(array)
count = countsubarray(array, size, k)
print(count, end=" ")

Output

16

Tips for Interview in Wipro:

Here are some tips for preparing for and approaching coding questions in a Wipro interview:

  • Brush up on programming fundamentals: Make sure you have a solid understanding of programming concepts such as data structures, algorithms, and object-oriented programming. Review these topics and practice coding exercises related to them.
  • Get familiar with programming languages and tools: Depending on the position you are applying for, the coding questions might focus on a specific programming language or toolset. Review the programming languages and tools relevant to the position, and practice coding exercises using them.
  • Practice coding problems: Practicing coding problems and exercises is one of the best ways to prepare for a coding interview. Websites such as prepbytes, HackerRank, and CodeSignal provide coding challenges and exercises that are similar to those you might encounter in a Wipro interview.
  • Be clear on the problem statement: When you are given a coding question, make sure you understand the problem statement and requirements clearly. Ask clarifying questions if necessary to make sure you have a complete understanding of what you need to do.
  • Break the problem down: Before you start coding, break the problem down into smaller, more manageable pieces. This will help you to stay organized and focused and will make it easier to tackle the problem one step at a time.
  • Write clean, well-organized code: When you are writing your code, make sure it is clean, well-organized, and easy to read. Use appropriate variable names, comments, and whitespace to make your code easy to understand.
  • Test your code: Before you submit your code, make sure to test it thoroughly to ensure that it works as expected. Try different input values and edge cases to make sure your code can handle a variety of scenarios.

Frequently Asked Questions(FAQ)

Here are some frequently asked questions (FAQ) related to Wipro’s coding round:

Question 1) What is the format of the Wipro coding round?
Answer: Wipro’s coding round might consist of multiple-choice questions, programming exercises, or both. The format might vary depending on the position you are applying for.

Question 2) What programming languages might be tested in the Wipro coding round?
Answer: The programming languages tested in the Wipro coding round might vary depending on the position you are applying for. It is important to review the job description and the company’s website to determine which programming languages are relevant.

Question 3) How can I prepare for the Wipro coding round?
Answer: To prepare for the Wipro coding round, you can review programming concepts such as data structures and algorithms, practice coding exercises, and become familiar with the programming languages and tools relevant to the position you are applying for.

Question 4) How much time is given for the Wipro coding round?
Answer: The amount of time given for the Wipro coding round might vary depending on the position and the complexity of the coding questions. It is important to manage your time effectively during the round to ensure that you can complete all the questions.

Question 5) Can I use external resources during the Wipro coding round?
Answer: It is unlikely that you will be allowed to use external resources during the Wipro coding round. However, it is important to review the specific guidelines provided by Wipro to determine what resources are allowed.

Question 6) Will I be able to use my own computer for the Wipro coding round?
Answer: The Wipro coding round might be conducted in a variety of formats, such as an online test or an in-person interview. Depending on the format, you might be able to use your own computer or you might be provided with a computer to use during the round.

Question 7) How are the coding round results evaluated?
Answer: The coding round results are evaluated based on factors such as the accuracy, efficiency, and readability of the code, as well as the problem-solving skills and thought processes demonstrated by the candidate.

Leave a Reply

Your email address will not be published. Required fields are marked *