You are on page 1of 7

Uzio PHIX Freshers Hiring Test  mnagpal786@gmail.

com

You can view this report online at : https://www.hackerrank.com/x/tests/1170716/candidates/28584080/report

Full Name: mayank nagpal

Email: mnagpal786@gmail.com scored in Uzio PHIX Freshers


0%
Test Name: Uzio PHIX Freshers Hiring Test Hiring Test in 73 min 56 sec on
0/140 10 Aug 2021 23:48:01 EDT
Taken On: 10 Aug 2021 23:48:01 EDT

Time Taken: 73 min 56 sec/ 75 min

Work Experience: < 1 years

Contact Number: +919540766755

Linkedin: https://www.linkedin.com/in/mayank-nagpal-
2446b51a1/

Invited by: Birajpal Singh

Invited on: 10 Aug 2021 23:44:44 EDT

Skills Score: Problem Solving (Basic) 0/50


Problem Solving (Intermediate) 0/75

Tags Score: Algorithms 0/75


Bitwise Operations 0/75
Brute Force 0/75
CPCE Questions 0/50
Easy 0/50
Filtering 0/50
Interviewer Guidelines 0/50
Medium 0/75
Problem Solving 0/125
Strings 0/125

Recruiter/Team Comments:

No Comments.

Question Description Time Taken Score Status

Q1 Output of Java Program  Subjective 14 min 57 sec 0/ 15 


Q2 How Many Words  Coding 54 min 7 sec 0/ 50 
Q3 Scatter-Palindrome  Coding 4 min 38 sec 0/ 75 

1/7
QUESTION 1 Output of Java Program 

Subjective

Not Submitted
QUESTION DESCRIPTION

Write the output of main method


Score 0

import java.io.*;
class Run {
static void rearrange(int a[], int size)
{
int positive = 0, negative = 1, temp;
while (true) {
while (positive < size && a[positive] >= 0)
positive += 2;
while (negative < size && a[negative] <= 0)
negative += 2;

if (positive < size && negative < size) {


temp = a[positive];
a[positive] = a[negative];
a[negative] = temp;
}
else
break;
}
}

public static void main(String args[]) {


int arr[] = {-1, 3, -5, 6, 3, 6, -7, -4, -9, 10};
int n = arr.length;
rearrange(arr, n);
for (int i = 0; i < n; i++){
System.out.print(arr[i] + " ");
}
}
}

CANDIDATE ANSWER

 This candidate has not answered this question.

No Comments

QUESTION 2 How Many Words 



Coding Easy Strings Filtering Problem Solving Interviewer Guidelines

CPCE Questions
Wrong Answer

QUESTION DESCRIPTION
Score 0
A sentence is made up of a group of words. Each word is a sequence of letters, ('a'-'z', 'A'-'Z'), that may
contain one or more hyphens and may end in a punctuation mark: period (.), comma (,), question mark (?),
or exclamation point (!). Words will be separated by one or more white space characters. Hyphens join two
words into one and should be retained while the other punctuation marks should be stripped. Determine
the number of words in a given sentence.

Example
s = 'How many eggs are in a half-dozen, 13?'
2/7
The list of words in the string is ['How', 'many', 'eggs', 'are', in', 'a', 'half-dozen'] and the number of words is
7. Notice that the numeric string, '13', is not a word because it is not within the allowed character set.

Function Description
Complete the function howMany in the editor below.

howMany has the following parameter(s):


sentence: a string

Returns:
int: an integer that represents the number of words in the string

Constraints
0 < length of s ≤ 105

Input Format For Custom Testing

The only line contains a string, sentence.

Sample Case 0

Sample Input

he is a good programmer, he won 865 competitions, but sometimes he dont.


What do you think? All test-cases should pass. Done-done?

Sample Output

21

Explanation
The substring '865' is not a word, so is not included in the count. The hyphenated words 'test-cases' and
'Done-done' each count as 1 word. The total number of words in the string is 21.

Sample Case 1

Sample Input

jds dsaf lkdf kdsa fkldsf, adsbf ldka ads? asd bfdal ds bf[l. akf dhj ds
878 dwa WE DE 7475 dsfh ds RAMU 748 dj.

Sample Output

21

Explanation
Note that the substring 'bf[l' is not a word because of the invalid character. Other substrings that are not
words are '878', '7475' and '748'. The total number of words in the string is 21.

INTERVIEWER GUIDELINES

Hint 1

Count the words separated by spaces.

Hint 2

A word can be numeric so just skip them.

Solution

Concepts covered: Basic Programming Skills, Loops, Strings, Problem Solving. The problem tests
the candidate's ability to use loops and handle strings. It requires the candidate to come up with an
algorithm to count the number of words in a sentence in a constrained time and space complexity.
3/7
Optimal Solution:
It's a basic implementation of strings. Just count the words separated by spaces and make sure to not
count numeric words.
Time Complexity: O(N)

def howMany(sentence):
i = 0
ans = 0
n = len(sentence)
# process all characters
while (i < n):
c = 0 # alphabetic character and dashes count
c2 = 0 # total character count
c3 = 0 # valid punctuation
# update character type counts until a space is reached
while (i < n and sentence[i] != ' '):
if ((sentence[i] >= 'a' and sentence[i] <= 'z') or
(sentence[i] >= 'A' and sentence[i] <= 'Z') or sentence[i] == '-'):
c += 1
elif (sentence[i] and (sentence[i] == ',' or sentence[i] ==
'.' or sentence[i] == '?' or sentence[i] == '!')):
c3 += 1
c2 += 1
i += 1
# end of word - add to word count only if
# valid characters count + valid punctuation count == all letters
count
# and some valid characters are present in the word
if (c + c3 == c2 and c > 0):
ans += 1
# skip all spaces
while (i < n and sentence[i] == ' '):
i += 1
return ans

Error Handling:
1. The words are separated by spaces and there might be multiple spaces in a sentence.
2. Numeric words(i.e. those words which consists of numbers ) should not be counted as a valid word.

Complexity Analysis

Time Complexity - O(n).


We make linear time operations on the input sentence.

Space Complexity - O(1) - No extra space is required.

CANDIDATE ANSWER

Language used: Java 8

1 class Result {
2
3 /*
4 * Complete the 'howMany' function below.
5 *
6 * The function is expected to return an INTEGER.
7 * The function accepts STRING sentence as parameter.
8 */
9
4/7
10 public static int howMany(String sentence) {
11 sentence= sentence.replaceAll("[A-za-z]", "");
12 String [] arr = sentence.split(" ");
13 return arr.length;
14 }
15
16 }
17
18

TESTCASE DIFFICULTY TYPE STATUS SCORE TIME TAKEN MEMORY USED

TestCase 0 Easy Sample case  Wrong Answer 0 0.0788 sec 23.7 KB

TestCase 1 Easy Sample case  Wrong Answer 0 0.0871 sec 23.8 KB

TestCase 2 Easy Sample case  Wrong Answer 0 0.0728 sec 23.6 KB

TestCase 3 Easy Sample case  Wrong Answer 0 0.0806 sec 23.7 KB

TestCase 4 Easy Hidden case  Wrong Answer 0 0.0763 sec 23.6 KB

TestCase 5 Easy Sample case  Wrong Answer 0 0.0806 sec 23.7 KB

TestCase 6 Easy Hidden case  Wrong Answer 0 0.1013 sec 23.7 KB

TestCase 7 Easy Hidden case  Wrong Answer 0 0.0763 sec 23.7 KB

TestCase 8 Easy Hidden case  Wrong Answer 0 0.0723 sec 23.9 KB

TestCase 9 Easy Hidden case  Wrong Answer 0 0.0717 sec 23.8 KB

TestCase 10 Easy Hidden case  Wrong Answer 0 0.1074 sec 32.8 KB

TestCase 11 Easy Hidden case  Wrong Answer 0 0.1302 sec 33 KB

TestCase 12 Easy Hidden case  Wrong Answer 0 0.1033 sec 33 KB

TestCase 13 Easy Hidden case  Wrong Answer 0 0.1282 sec 32.6 KB

TestCase 14 Easy Hidden case  Wrong Answer 0 0.1207 sec 33.1 KB

No Comments

QUESTION 3 Scatter-Palindrome 

Coding Algorithms Strings Bitwise Operations Brute Force

Problem Solving Medium


Not Submitted

QUESTION DESCRIPTION
Score 0
A palindrome is a string which reads the same forward and backwards, for example, tacocat and mom. A
string is a scatter-palindrome if its letters can be rearranged to form a palindrome. Given an array
consisting of n strings, for each string, determine how many of its substrings are scatter-palindromes. A
substring is a contiguous range of characters within the string.

Example
strToEvaluate = ['aabb']

The scatter-palindromes are a, aa, aab, aabb, a, abb, b, bb, b. There are 9 substrings that are scatter-
palindromes.

Function Description
Complete the scatterPalindrome function in the editor below.

scatterPalindrome has one parameter:


ti tT E l t [ ] th ti t b l t d
5/7
string strToEvaluate[n]: the n strings to be evaluated
Returns
int[n]: each element i represents the number of substrings of strToEvaluate[i] which are scatter-
palindromes.

Constraints
1 ≤ n ≤ 100
1 ≤ size of strToEvaluate[i] ≤ 1000
all characters of strToEvaluate[i] ∈ ascii[a-z]

Input Format For Custom Testing

The first line contains an integer, n, that denotes the number of elements in strToEvaluate.
Each line i of the n subsequent lines (where 0 ≤ i < n) contains a string that describes strToEvaluate[i].

Sample Case 0

Sample Input For Custom Testing

STDIN Function
----- --------
1 → strToEvaluate[] size n = 1
abc → strToEvaluate = [ "abc" ]

Sample Output

Explanation
The substrings that are scatter-palindromes of the string abc are:
a
b
c

Sample Case 1

Sample Input For Custom Testing

STDIN Function
----- --------
1 → strToEvaluate[] size n = 1
bbrrg → strToEvaluate = [ "bbrrg" ]

Sample Output

12

Explanation
The substrings that are scatter-palindromes of the string bbrrg are:
b
bb
bbr
bbrr
bbrrg
b
brr
r
rr
rrg
r
g

CANDIDATE ANSWER

6/7
 No answer was submitted for this question. Showing compiled/saved versions.

Language used: Java 8

1 class Result {
2
3 /*
4 * Complete the 'scatterPalindrome' function below.
5 *
6 * The function is expected to return an INTEGER_ARRAY.
7 * The function accepts STRING_ARRAY strToEvaluate as parameter.
8 */
9
10 public static List<Integer> scatterPalindrome(List<String> strToEvaluate)
11 {
12 // Write your code here
13
14 }
15
16 }
17

No Comments

PDF generated at: 11 Aug 2021 05:03:15 UTC

7/7

You might also like