Aricent Interview Question for Software Engineers


Country: India
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
0
of 0 vote

/* IMPORTANT: Multiple classes and nested static classes are supported */

// uncomment this if you want to read input.
//imports for BufferedReader
import java.io.BufferedReader;
import java.io.InputStreamReader;
//import for Scanner and other utility classes
import java.util.*;


class TestClass {
public static void main(String args[] ) throws Exception {
/*
* Read input from stdin and provide input before running
* Use either of these methods for input
*/
//BufferedReader
Scanner s = new Scanner(System.in);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n;
n = s.nextInt();
HashMap<String,Integer> hm=new HashMap<String,Integer>();
int var = 0;
for(int i = 0; i < n; i++)
{
String line = br.readLine();
int ind = line.indexOf("=");
if(ind == -1)
{
continue;
}
// System.out.println("ind = " + ind);
String temp = line.substring(0,ind-1);
// System.out.println("temp = " + temp);
if(hm.get(temp) == null)
{
hm.put(temp, 1);
var++;
}

// int N = Integer.parseInt(line);

//Scanner


}

System.out.println(var);
}
}

/*2
foo = 3;
bar = 4;
*/

- chanfool21 February 19, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/* IMPORTANT: Multiple classes and nested static classes are supported */

 // uncomment this if you want to read input.
//imports for BufferedReader
import java.io.BufferedReader;
import java.io.InputStreamReader;
//import for Scanner and other utility  classes
import java.util.*;


class TestClass {
    public static void main(String args[] ) throws Exception {
        /*
         * Read input from stdin and provide input before running
         * Use either of these methods for input
        */
        //BufferedReader
        Scanner s = new Scanner(System.in);
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n;
        n = s.nextInt();
        HashMap<String,Integer> hm=new HashMap<String,Integer>();
        int var = 0;
        for(int i = 0; i < n; i++)
       {
            String line = br.readLine();
            int ind = line.indexOf("=");
            if(ind == -1)
            {
                continue;
            }
           // System.out.println("ind = " + ind);
            String temp = line.substring(0,ind-1);
           // System.out.println("temp = " + temp);
            if(hm.get(temp) == null)
            {
                hm.put(temp, 1);
                var++;
            }
            
      //  int N = Integer.parseInt(line);
        
        //Scanner
        
        
       }
       
       System.out.println(var);
    }
}

/*2
foo = 3;
bar = 4;
*/

- chanfool21 February 19, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/* IMPORTANT: Multiple classes and nested static classes are supported */

 // uncomment this if you want to read input.
//imports for BufferedReader
import java.io.BufferedReader;
import java.io.InputStreamReader;
//import for Scanner and other utility  classes
import java.util.*;


class TestClass {
    public static void main(String args[] ) throws Exception {
        /*
         * Read input from stdin and provide input before running
         * Use either of these methods for input
        */
        //BufferedReader
        Scanner s = new Scanner(System.in);
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n;
        n = s.nextInt();
        HashMap<String,Integer> hm=new HashMap<String,Integer>();
        int var = 0;
        for(int i = 0; i < n; i++)
       {
            String line = br.readLine();
            int ind = line.indexOf("=");
            if(ind == -1)
            {
                continue;
            }
           // System.out.println("ind = " + ind);
            String temp = line.substring(0,ind-1);
           // System.out.println("temp = " + temp);
            if(hm.get(temp) == null)
            {
                hm.put(temp, 1);
                var++;
            }
            
      //  int N = Integer.parseInt(line);
        
        //Scanner
        
        
       }
       
       System.out.println(var);
    }
}

/*2
foo = 3;
bar = 4;
*/

- Anonymous February 19, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The question is ill posed - with the definition of identifier being a string.
Yes, identifiers are a special string - but not any string. One should formulate the problem as token matching using regex.

<ID> := [a-zA-Z_][a-zA-Z_0-9]* 
assignment -> ID  '='  [0-9]+  ';'

and we are good. Clearly in this form, we can make the assignment itself a regex and can use named patterns and that is the answer.

- NoOne February 19, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

something along the lines of the following could work as a simple linux command. not sure this is 100% accurate but the idea is you search for all alphanumeric strings of size 1 or more followed by an equal sign separated by 0 or more spaces, remove the equals sign and subsequent white space, sort by unique values and count the remaining lines. may not be what the interviewer is looking for but at very least worth mentioning.

grep '[a-zA-Z0-9]+ *=' | sed %'='%''% | trim | sort -u | wc -l

- Anonymous February 20, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

var fs=require('fs');
fs.readFile(__dirname + '/' +'testVariable.js','utf-8',(err,data)=>{
if(err){
console.log("Err :",err);
}
data=data.split(';');
var res=[];
for(let i=0;i<data.length;i++){
let str=data[i].split('=')[0]
str=str.replace(new RegExp("var", 'g'), '').trim();
if(str){
res.push(str);
}

}
console.log("res :",res);
});

- Shubham Verma June 01, 2019 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More