HCL Coding Answer
HCL Coding Answer
Curriculum Vitae
ADARSH S SRIVASTAV
Address : Gachibowli, Hyderabad-500032
Mob: +91- 7406962012
E-mail: adrshsrivastav@gmail.com
Carrier Objective
Intend to build a career with leading corporate infused with hi-tech environment comprised of
committed & dedicated people, which will help me in evolving myself and making a rewarding
and enriched career.
Work Experience
Samsung R&D Institute Bangalore 17th July 2014 – 6th June 2016
Designation : Sr. Software Engineer
- Understanding of Display Framework, Boot loader, Schedulers, Display Drivers
- Worked on an Automation tool for SOC testing: Frame buffer Driver Testing, Passing
parameters to kernel while booting.
- Boot loader code enhancement, testing and porting.
Educational Background
CPI
Year University/
Examination Institute /Perce
Board
ntage
M Tech(IT) 2014 IIIT-Allahabad IIIT-A 8.6
Technical Skills
Educational Projects
Thesis [M Tech ]
Project Title Stock Trend Prediction of Indian Market using a hybrid model of SVM-
ABC and a modified technical indicator
Duration 1 Year
Description The proposed SVM-ABC model along with a set of technical indicators
Academic Achievements
Declaration:
I hereby declare that above information is correct to the best of my knowledge and belief.
ADARSH S. SRIVASTAV
Developer Interview
Participant
Given a string comprised of lowercase letters in the range ascii[a-z], determine the length of the smallest substring
that contains all of the letters present in the string.
For example, given the string s = dabbcabcd, the list of all characters in the string is [a, b, c, d]. Two of the
substrings that contain all letters are dabbc and abcd. The shortest substring containing all the letters is 4
characters long, abcd.
Function Description
Complete the function shortestSubstring in the editor below. The function must return the length of the shortest
substring that contains all of the characters within S.
s: a string
bab
Sample Output
Explanation
Code Output
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
class Result {
/*
* Complete the 'shortestSubstring' function below.
*
* The function is expected to return an INTEGER.
* The function accepts STRING s as parameter.
*/
public static int shortestSubstring(String s) {
char[] mainStr = s.toCharArray();
int[] cmap = new int[200];
String subStr = "";
for(int i=0; i<mainStr.length; i++)
{
if(cmap[(int) mainStr[i]] == 0)
{
subStr += mainStr[i];
cmap[(int) mainStr[i]] = 1;
}
}
if (count == charSubStr.length)
{
iStr = (int)mainStr[start];
while(matchStrCount[iStr] > subStrCountDict[iStr] || subStrCountDict[iStr]
== 0)
{
}
}
//System.out.println(s.substring(starti, starti+maxLenWindow));
return maxLenWindow;
}
}
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new
InputStreamReader(System.in));
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv(
"OUTPUT_PATH")));
String s = bufferedReader.readLine();
int result = Result.shortestSubstring(s);
bufferedWriter.write(String.valueOf(result));
bufferedWriter.newLine();
bufferedReader.close();
bufferedWriter.close();
}
}
A binary tree is a multi-node data structure where each node has, at most, two child nodes
and one stored value. It may either be:
• An empty tree, where the root is null.
• A tree with a non-null root node that contains a value and two subtrees, left and right,
which are also binary trees.
A binary tree is a binary search tree (BST) if all the non-null nodes exhibit two properties:
• Each node's left subtree contains only values that are lower than its own stored value.
• Each node's right subtree contains only values that are higher than its own stored value.
A pre-order traversal is a tree traversal method where the current node is visited first, then
the left subtree, and then the right subtree. The following pseudocode parses a tree into a list
using pre-order traversal:
• If the root is null, output the null list.
• For a non-null node:
1. Make a list, left, by pre-order traversing the left subtree.
2. Make a list, right, by pre-order traversing the right subtree.
3. Output the stored value of the non-null node, append left to it, then append right to
the result.
For more detail, see the diagram in the Explanation section below.
Write a program to test whether a traversal history could describe a path on a valid BST.
Return YES on a new line if the path can be in a valid BST, or NO if it cannot.
Function Description
Complete the function isValid in the editor below. The function must return a string denoting
YES if the path can be in a valid BST, or NO if it cannot.
Sample Input 0
5
3
1 3 2
3
2 1 3
6
3 2 1 5 4 6
4
1 3 4 2
5
3 4 5 1 2
Sample Output 0
YES
YES
YES
NO
NO
Code Output
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
class Result {
/*
* Complete the 'isValid' function below.
*
* The function is expected to return a STRING.
* The function accepts INTEGER_ARRAY a as parameter.
*/
public static String isValid(List<Integer> a) {
Stack<Integer> stack = new Stack<Integer>();
int mid = -1;
for(int i=0; i<a.size(); i++)
{
int ele = a.get(i);
if(ele < mid)
return "NO";
}
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new
InputStreamReader(System.in));
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv(
"OUTPUT_PATH")));
int q = Integer.parseInt(bufferedReader.readLine().trim());
IntStream.range(0, q).forEach(qItr -> {
try {
int aCount = Integer.parseInt(bufferedReader.readLine().trim());
List<Integer> a = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", ""
).split(" "))
.map(Integer::parseInt)
.collect(toList());
String result = Result.isValid(a);
bufferedWriter.write(result);
bufferedWriter.newLine();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
});
bufferedReader.close();
bufferedWriter.close();
}
}