PwC Coding Questions and Answers
Most Asked PwC Coding Questions with Solutions
Find the most asked PWC Coding Questions and answers 2023, asked for freshers in various hiring exams. If you are preparing for PwC recruitment examinations you can refer to this page for more information.
About PwC
PricewaterhouseCoopers is an international professional service brand of firms that work under PwC. It is considered one of the Big Four accounting firms along with Deloitte, EY and KPMG.
Prime Course Trailer
PwC Recruitment Process
- Online Tests
- Interview
PwC Online Test
Round Name | Number of Questions |
---|---|
Aptitude | 15 questions |
Verbal | 5 questions |
Conceptual CS | 20 questions |
Quality Mindset | 5 questions |
Programming | 1 question |
PwC Eligibility Criteria
PwC hires both B.Tech and MCA graduates. The eligibility criteria for both the departments are:
2. Minimum marks of 60%
3. Graduation completed in one attempt
2. Minimum marks of 60%
3. Post Graduation completed in one attempt
PwC Salary
PwC offers a package of 6 lakhs per annum. It is fixed pay wit no variables.
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Sample PwC Coding Questions and Answers 2023
QUESTION : Order check
Problem Statement: In an IT company there are n number of Employees , they are asked to stand in ascending order according to their heights.But some employees are not currently standing in their correct position.
Your task is to find how many employees are there who are not standing in their correct positions.
Example
height=[1,2,1,3,3,4,3]
The 4 employees at indices 1,2,5 and 6 are not in the right positions. The correct positions are (1,1,2,3,3,3,4).Return 4.
Function Description
Complete the function countEmployees in the editor below.
count Employee has the following parameter(s):
int height[n]:an array of heights in the order the employees are standing
Returns:
Int : the number of employees not standing in the correct positions
Constraints
- 1<=n<=10^5
- 1<=height[i]<=10^9
Sample case 0
Sample input 0
7 ->height[] size n=7
1
2
1
3
3
4
3
Sample output 0:
4
Explanation
The four employees who are not standing in the correct positions are at indices [1,2,5,6] return 4. The correct positions are [1,1,2,3,3,3,4].
import java.util.*; public class Main { public static int countEmployees (int arr[]) { int n = arr.length; int temp[] = new int[n]; for (int i = 0; i < n; i++) temp[i] = arr[i]; Arrays.sort (arr); int count = 0; for (int i = 0; i < n; i++) if (arr[i] != temp[i]) count++; return count; } public static void main (String[]args) { Scanner sc = new Scanner (System.in); int n = sc.nextInt (); int arr[] = new int[n]; for (int i = 0; i < n; i++) arr[i] = sc.nextInt (); System.out.println (countEmployees (arr)); } }
def countEmployees(n,arr): dup_arr=arr[:] dup_arr.sort() count=0 for i in range(n): if arr[i]!=dup_arr[i]: count+=1 else: pass return count n=int(input()) arr=[ ] for i in range(n): arr.append(int(input())) print(countEmployees(n,arr))
QUESTION : Maximum Toys
In a toy shop there are a number of toys presented with several various – priced toys in a specific order. You have a limited budget and would like to select the greatest number of consecutive toys that fit within the budget. Given prices of the toys and your budget, what is the maximum number of toys that can be purchased for your child?
Example:
prices=[1,4,5,3,2,1,6]
money=6
All sub arrays that sum to less than or equal to 6 .
length 1: [1] [4] [5] [3] [2] [1] [6]
length 2: [1,4] [3,2] [2,1]
length 3: [3,2,1]
The longest of these or the maximum number of toys that can be purchased is 3.
Function description
Complete the function getMaxToys in the editor below
getMaxToys has the following parameters:
int prices[n] : the prices of the various toys
int money: the amount of money you can spend on toys
Returns
Int the maximum number of toys you can purchase
Constraints
1<=n<=10^5
1<=price[i]<=100
1<=money<=10^6
Sample case
Sample input 0
7->n=7
1-> price[]=[1,4,5,3,2,1,6]
4
5
3
2
1
6
Sample Output
6 ->money=6
import java.util.*; public class Main { public static int getMaxToys (int prices[], int money) { int sum = 0; int count = 0; int max = 0; for (int i = 0; i < prices.length; i++) { sum = count = 0; for (int j = i; j < prices.length; j++) { if ((sum + prices[j]) <= money) { sum = sum + prices[j]; count = count + 1; max = Math.max (count, max); } else { count = 0; sum = 0; break; } } } return max; } public static void main (String[]args) { Scanner sc = new Scanner (System.in); int n = sc.nextInt (); int prices[] = new int[n]; for (int i = 0; i < n; i++) prices[i] = sc.nextInt (); int money = sc.nextInt (); System.out.println (getMaxToys (prices, money)); } }
def getMaxToys(n,arr,money): L,H=0,n-1 while(L<=H): if(sum(arr[L:H+1])<=money): break else: if arr[L]>arr[H]: L+=1 else: H-=1 return (H-L+1) n=int(input()) arr=[] for i in range(n): arr.append(int(input())) money=int(input()) print(getMaxToys(n,arr,money))
QUESTION : Formatting large Products
Rohan is weak in mathematics.He is giving mathematics Olympiad , but he got stuck in one of the question .Help rohan to solve the question.In Question there are two positive integer A and B. You have to find the product of all integer between A and B which is represented in the form C=D*10^E , where C is the product of numbers , D and E are non-negative integers and the last digit of D is non-zero.
Function Description
Complete the function formatProducts in the editor below, formatProduct must return a string that represents C in the above described form.
Function has the following parameters
A: an integer
B: an integer
Constraints
- A will between 1 and 1,000,000 . Inclusive.
- B will be between A and 1,000,000. Inclusive.
Sample Input 0
1
5
Sample Output 0
12 * 10^1
Explanation
1*2*3*4*5=120 = 12 * 10^1
Sample Input 1
3
10
Sample Output 1
18144 * 10^2
Explanation
3*4*….*10=1814400 =18144 * 10^2
import java.util.*; public class Main { public static String formatProducts (int a, int b) { int result = 1; for (int i = a; i <= b; i++) result = result * i; int temp = result; int power = 0; while ((result % 10) == 0) { power = power + 1; result = result / 10; } return result + " * 10^" + power; } public static void main (String[]args) { Scanner sc = new Scanner (System.in); int a = sc.nextInt (); int b = sc.nextInt (); System.out.println (formatProducts (a, b)); } }
def formatProducts(L,H): a=1 for i in range(L,H+1): a=a*i c=0 while(True): if a%10!=0: break else: c+=1 a=a//10 return (str(a)+" * 10^"+str(c)) L=int(input()) H=int(input()) print(formatProducts(L,H))
QUESTION : Copycat in exam (R->Medium)
Rahul copies in the exam from his adjacent students. But he doesn’t want to be caught, so he changes words keeping the letter constant. That means he interchanges the positions of letters in words. You are the examiner and you have to find if he has copied a certain word from the one adjacent student who is giving the same exam, and give Rahul the markings he deserves.
Note that: Uppercase and lowercase are the same.
Input Format:
First line with the adjacent student’s word
Second line with Rahul’s word
Output Format:
0 if not copied
1 if copied
Constraints:
1<=Length of string<=10^6
Sample Input:
CAR
ACR
Sample Output:
1
import java.util.*; public class Main { public static void main (String[]args) { Scanner sc = new Scanner (System.in); String s1 = sc.next (); String s2 = sc.next (); s1 = s1.toUpperCase (); s2 = s2.toUpperCase (); char arr1[] = s1.toCharArray (); Arrays.sort (arr1); char arr2[] = s2.toCharArray (); Arrays.sort (arr2); String res1 = new String (arr1); String res2 = new String (arr2); if (res1.equals (res2)) System.out.println ("1"); else System.out.println ("0"); } }
s=input() s1=input() s=s.lower() s=sorted(s) s1=s1.lower() s1=sorted(s1) if s1==s: print(1) else: print(0)
#include<bits/stdc++.h> using namespace std; int main() { string s2,s1; cin>>s1>>s2; transform(s1.begin(),s1.end(),s1.begin(),::tolower); transform(s2.begin(),s2.end(),s2.begin(),::tolower); sort(s1.begin(),s1.end()); sort(s2.begin(),s2.end()); cout<< (s2==s1); }
QUESTION : Mr. Robot’s Password (R)
Mr. Robot is making a website, in which there is a tab to create a password. As other websites, there are rules so that the password gets complex and none can predict the password for another. So he gave some rules like:
– At least one numeric digit
– At Least one Small/Lowercase Letter
– At Least one Capital/Uppercase Letter
– Must not have space
– Must not have slash (/)
– At least 6 characters
If someone inputs an invalid password, the code prints: “Invalid password, try again”.
Otherwise, it prints: “password valid”.
Input Format:
A line with a given string as a password
Output Format:
If someone inputs an invalid password, the code prints: “Invalid password, try again”.
Otherwise, it prints: “password valid”, without the quotation marks.
Constraints:
Number of character in the given string <=10^9
Sample input 1:
abjnlL09
Sample output 1:
password valid
Sample input 2:
jjnaskpk
Sample output 2:
Invalid password, try again
#include<bits/stdc++.h> using namespace std; int CheckPassword (char str[], int n) { if (n < 4) return 0; int a = 0, cap = 0, nu = 0, low = 0; while (a < n) { if (str[a] == ' ' || str[a] == '/') return 0; if (str[a] >= 65 && str[a] <= 90) { cap++; } if (str[a] - 32 >= 65 && str[a] - 32 <= 90) { low++; } else if (str[a] - '0' >= 0 && str[a] - '0' <= 9) nu++; a++; } return cap > 0 && nu > 0 && low > 0; } int main () { string s; getline (cin, s); int len = s.size (); char *c = &s[0]; if (CheckPassword (c, len)) cout << "password valid"; else cout << "Invalid password, try again"; }
def CheckPassword(s, n): if n < 4: return 0 cap = 0 nu = 0 lo = 0 for i in range(n): if s[i] == " " or s[i] == "/": return 0 if s[i] >= "A" and s[i] <= "Z": cap += 1 if s[i] >= "a" and s[i] <= "z": lo += 1 elif s[i].isdigit(): nu += 1 if cap > 0 and nu > 0 and lo > 0: return 1 else: return 0 s = input() a = len(s) if CheckPassword(s, a): print("password valid") else: print("Invalid password, try again")
FAQs on PwC Coding Questions with Solutions
Question 1: Are there any coding questions asked in PwC?
Yes, for technical profiles PwC asks coding questions. On this page, we have provided all the PwC Coding Questions
Question 2: Is PwC exam difficult to crack?
PwC exam is definitely tricky. They put emphasis on analytical thinking and problem solving skills of the candidate.
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment