# CoCubes Coding Questions & Solutions 2024, Get Solved Questions

## CoCubes Coding Questions & Solutions 2024 | CoCubes Coding Questions | CoCubes Coding Questions & Answers | CoCubes Online Coding Test Questions

CoCubes Coding Questions & Solutions 2024: The Company of CoCubes is hiring the various vacancies for eligible employees. Following of hiring, CoCubes 2024 for capable and eligible candidates. The selection process of CoCubes 2024 is Online Assessment Test, Interview Process, etc., Willing candidates eagerly prepare the interview process. CoCubes Coding Questions & Answers and CoCubes Coding Questions is available in this page. The Wipro will conduct many selections process. so, for candidates prepare common questions. CoCubes Coding questions with solutions contains mostly common and repeated asked questions. So, Candidates hopefully prepare the CoCube coding interview questions and answers.
The CoCubes Company published some sample CoCubes coding questions and answers/ CoCubes coding questions in the official website. Interested candidates must prepare the CoCubes Selection Process. When you will be qualified in the selection process, they will get Wipro Jobs. Candidates put your full efforts in the preparation of CoCubes Coding questions with Answers and CoCubes Coding Interview questions. Continuous preparation of CoCubes Coding questions and Answers, you definitely achieve the selection process. The Interview & test date will be intimated on mail. Keep check the mail.

### CoCubes Coding Questions and Answers

Q) Given a string consisting of only 0, 1, A, B, C where
A = AND
B = OR
C = XOR
Calculate the value of the string assuming no order of precedence and evaluation is done from left to right.

Constraints – The length of string will be odd. It will always be a valid string.
Example, 1AA0 will not be given as an input.

Examples:

Input: 1A0B1

Output : 1 1 AND 0 OR 1 = 1 Input : 1C1B1B0A0 Output : 0
C Program

```#include <stdio.h>
#include <string.h>
int evaluateBoolExpr(char* s)
{
int n = strlen(s);
for (int i = 0; i < n; i += 2)
{
// If operator next to current operand
// is AND.
if (i + 1 < n && i + 2 < n)
{
if (s[i+1] == 'A')
{
if (s[i+2] == '0'||s[i] == '0')
s[i+2] = '0';
else
s[i+2] = '1';
}
// If operator next to current operand
// is OR.
else if ((i + 1) < n && s[i+1] == 'B')
{
if (s[i+2] == '1'||s[i] == '1')
s[i+2] = '1';
else
s[i+2] = '0';
}
// If operator next to current operand
// is XOR (Assuming a valid input)
else
{
if (s[i+2] == s[i])
s[i+2] = '0';

else
s[i+2] = '1';
}
}
}
return s[n-1] - '0';
}
int main()
{
char str[100];
scanf("%[^\n]s",str);
int result = evaluateBoolExpr(str);
printf("%d",result);
}

Java Program```
```// Java program to evaluate value of an expression.
class Main
{

// Evaluates boolean expression
// and returns the result
static int evaluateBoolExpr (StringBuffer s)
{
int n = s.length ();

// Traverse all operands by jumping
// a character after every iteration.
for (int i = 0; i < n; i += 2)
{

// If operator next to current operand
// is AND.
if (i + 1 < n && i + 2 < n)
{
if (s.charAt (i + 1) == 'A')
{
if (s.charAt (i + 2) == '0'||s.charAt (i) == 0)
s.setCharAt (i + 2, '0');
else
s.setCharAt (i + 2, '1');
}

// If operator next to current operand
// is OR.
else if ((i + 1) < n && s.charAt (i + 1) == 'B')
{
if (s.charAt (i + 2) == '1'||s.charAt (i) == '1')
s.setCharAt (i + 2, '1');
else
s.setCharAt (i + 2, '0');
}

// If operator next to current operand
// is XOR (Assuming a valid input)
else
{
if (s.charAt (i + 2) == s.charAt (i))
s.setCharAt (i + 2, '0');
else
s.setCharAt (i + 2, '1');
}
}
}
return s.charAt (n - 1) - '0';
}

// Driver code
public static void main (String[]args)
{
String s = "1C1B1B0A0";
StringBuffer sb = new StringBuffer (s);
System.out.println (evaluateBoolExpr (sb));
}
}```

Python Program

```def solve(s):
s=s.replace("A","&").replace("B","|").replace("C","^")
return eval(s)

s=input()
print(solve(s))
```

Q) Make a function which accepts a string as an argument that may contain repetitive characters. Implement the function to modify and return the input string, such that each character once, along with the count of consecutive occurrence. Do not append count if the character occurs only once.

Note –

• The string will only contain lowercase English Alphabets
• If you have to manipulate the input string in place you cant use another string

Assumption –
No character will occur consecutively more than 9 times.

Example –

Input
aaaaabbbccccccccdaa

Output
a4b3c8da2

Java Program

```import java.util.Scanner;
public class Main
{
public static void main (String[]args)
{
try (Scanner sc = new Scanner (System.in);
)
{
StringBuilder sb = new StringBuilder (sc.nextLine ());
int count = 1;
char current = sb.charAt (0), next;
for (int i = 1; i < sb.length (); i++)
{
next = sb.charAt (i);
if (next == current)
{
sb.deleteCharAt (i);
i = i - 1;
count++;
}
else
{
sb.insert (i, count);
count = 1;
current = next;
i = i + 1;
}
}
sb.append (count);
System.out.println (sb);
}
}
}```
Python Program
```def solve(s):
ans=""
c=1
for i in range(len(s)-1):
if(s[i]==s[i+1]):
c+=1
else:
if(c==1):
ans+=s[i]
else:
ans+=s[i]+str(c)
c=1
if(c==1):
ans+=s[i+1]
else:
ans+=s[i+1]+str(c)
return ans

s=input()
print(solve(s))
```

Q) Write a function which accepts a string str, implement the function to find and return the minimum characters required to append at the end of str to make it a palindrome

Assumptions –
The string will only contain lowercase English Alphabets

Note –

• If string is already a palindrome then return NULL
• You have to find the minimum characters required to append at the end of the string to make it a palindrome

Example –

Input –
abcdc

Output –
ba

Java Program

```import java.util.Scanner;
public class Main
{

public static void main (String[]args)
{
try (Scanner sc = new Scanner (System.in);
)
{
StringBuilder sb = new StringBuilder (sc.nextLine ());
StringBuilder s = new StringBuilder ();
Boolean finish = true;
while (finish)
{
if (isPalindrome (sb))
{
System.out.println("NULL");
finish = false;
}

else
{
s.append (sb.charAt (0));
sb = new StringBuilder (sb.substring (1));
}
}
System.out.println (s.reverse ());
}
}
public static Boolean isPalindrome (StringBuilder sb)
{
int l = sb.length () / 2;
int m = sb.length () - 1;
for (int i = 0; i <= l; i++)
{
if (!(sb.charAt (i) == sb.charAt (m - i)))
return false;
}
return true;
}

}```
Python Program
```def ispalindrome(s):
return s==s[::-1]

def solve(s):
if(ispalindrome(s)):
return None
for i in range(len(s)):
x=s[:i][::-1]
if(ispalindrome(s+x)):
return x

s=input()
print(solve(s))
```

Q) Write a function which returns an integer based on some conditions. You were given with two integers as input say n and m

• if n>m return (n*m)-(n-m)
• if n<=m return (m%n)-(m+n)

Example:

Sample input:
n=10
m=18

Sample output:
-20

Explanation:
m%n=18%10=8
m+n=28

C program

```#include <stdio.h>
#include <string.h>
int solve(int n,int m)
{
if(n>m)
return (n*m)-(n-m);
else
return (m%n)-(m+n);
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int result = solve(n,m);
printf("%d",result);
}

C++ Program
```
```#include <iostream>

using namespace std;
int solve(int n,int m)
{
if(n>m)
return (n*m)-(n-m);
else
return (m%n)-(m+n);
}
int main()
{
int n,m;
cin>>n>>m;
int result = solve(n,m);
cout<< result;
return 0;
}

Java Program
```
```import java.util.Scanner;
import java.io.*;

class Main {
public static void main (String[] args) {
Scanner prep = new Scanner( System.in );
int n,m;
n= prep.nextInt();
m= prep.nextInt();
System.out.println(solve(n,m));
}
public static int solve(int n, int m)
{
if(n>m)
return (n*m)-(n-m);
else
return (m%n)-(m+n);
}
}```

Python Program

```def solve(n,m):
if(n>m):
return (n*m)-(n-m)
else:
return (m%n)-(m+n)
n=int(input())
m=int(input())
print(solve(n,m))```

Q) Write a function which returns the sum of elements whose frequency in the array is odd. Means find sum of elements whose Number of occurrences is odd

Example:

Input:
15
arr=[1,1,2,2,2,3,4,4,5,5,5,5,6,7,7]

Output:
11

Explanation:
count of each element is as follows-
1–>2, 2–>3, 3–>1, 4–>2, 5–>4, 6–>1, 7–>2
Odd number of time occured elements are, 2,3,6 and its sum if 11

Python Program

```def solve(arr,n):
count=0
for i in set(arr):
if(arr.count(i)%2==1):
count+=i
return count

n=int(input())
arr=list(map(int,input().split()))
print(solve(arr,n))
```

Q) Write a function to return the count of  alphanumeric characters in a given string.(Count number of alphabets and numerics in a string)

Example :

Input:
Hello World!123

Output:
13

```C Program
```
```#include <stdio.h>
#include<string.h>
int solve(char str[])
{

int count= 0;
for (int i = 0; str[i]!='\0'; i++)
{
if ((str[i] >= 'A' && str[i] <= 'Z')|| (str[i] >= 'a' && str[i] <= 'z') )
count++;
if(str[i] >= '0' && str[i] <= '9')
count++;
}

return count;
}

int main()
{
char str[]= "Hello World!123";
printf("%d",solve(str));
return 0;
}```
C++ Program
```#include <iostream>
using namespace std;

int solve(string str)
{

int count= 0;
for (int i = 0; i < str.length(); i++)
{
if ((str[i] >= 'A' && str[i] <= 'Z')|| (str[i] >= 'a' && str[i] <= 'z') )
count++;
if(str[i] >= '0' && str[i] <= '9')
count++;
}

return count;
}

int main()
{
string str = "Hello World!123";
cout<< solve(str);
return 0;
}```

Java Program

```import java.util.Scanner;
import java.io.*;

class Main {
public static void main (String[] args) {
System.out.println(solve("Hello World!123"));
}
public static int solve(String str)
{
int count= 0;
char[] str1 = str.toCharArray();
for (int i = 0;i< str1.length; i++)
{
if ((str1[i] >= 'A' && str1[i] <= 'Z')|| (str1[i] >= 'a' && str1[i] <= 'z') )
count++;
if(str1[i] >= '0' && str1[i] <= '9')
count++;
}

return count;
}
}```
```Python Program
```
```def solve(str):
count=0
for i in str:
if(i.isalpha() or i.isnumeric()):
count+=1
return count

n=input()
print(solve(n))```

### CoCubes Online Test Questions & Answers

 JOB ALERT ON INSTAGRAM FOLLOW NOW>> JOB ALERT ON YOUR EMAIL DAILY SUBSCRIBE NOW>>
` `

### Govt Jobs by Qualifications

Education & Vacancies Salary Apply Link
10th Pass Govt Jobs - 5,000 Vacancies Rs. 5,200 - 63,200 Apply Now
12th Pass Govt Jobs - 18,000+ Vacancies Rs. 5,200 - 92,300 Apply Now
ITI Pass Jobs - 3,500 Vacancies Rs. 5,200 - 35,000 Apply Now
Any Graduate Jobs - 19,100 Vacancies Rs. 5,200 - 92,300 Apply Now
Central Govt Jobs Rs. 5,200 - 17,000 Apply Now
Bank Jobs - 1,000 Vacancies Rs. 5,200 - 29,200 Apply Now
Diploma Jobs - 9,300 Vacancies Rs. 5,200 - 35,000 Apply Now
BTech/BE Jobs - 18,000 Vacancies Rs. 15,000 - 1,00,000 Apply Now
Data Entry Jobs - 1,300 Vacancies Rs. 5,200 - 29,200 Apply Now
Private Jobs Rs. 10,000 - 67,700 Apply Now