Indeed Interview Question for SDE-2s


Country: United States




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

Delta encoding

- Nits August 16, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static List<String> serialize(int ar[]){
int pre = ar[0];
List<String> res = new ArrayList<>();
for(int i=1;i<ar.length;i++){
if(ar[i]-ar[i-1]==1){
continue;
} else {
res.add(pre+"-"+ar[i-1]);
pre=ar[i];
}
}
res.add(""+pre);
return res;
}

- Anonymous November 01, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static List<String> serialize(int ar[]){
        int pre = ar[0];
        List<String> res = new ArrayList<>();
        for(int i=1;i<ar.length;i++){
            if(ar[i]-ar[i-1]==1){
                continue;
            } else {
                res.add(pre+"-"+ar[i-1]);
                pre=ar[i];
            }
        }
        res.add(""+pre);
        return res;
    }

- San November 01, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

replace {{ res.add(""+pre) }} with

{{
int last = ar[ar.length - 1];
res.add((num == last) ? "" + pre : pre + "-" + last);
}}

- arsh July 30, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

replace {{ res.add(""+pre) }} with

{{ int last = ar[ar.length - 1]; }}
{{ res.add((num == last) ? "" + pre : pre + "-" + last); }}

- arsh July 30, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static String encode(int[] arr) {
    	if (arr == null || arr.length == 0) {
    		throw new IllegalArgumentException("input array is null or empty");
    	}
    	
    	if (arr.length == 1) {
    		return Integer.toString(arr[0]);
    	}
    	
    	int start = arr[0];
    	int end = arr[0]; 
    	StringBuilder sb = new StringBuilder();
    	
    	for (int i = 1; i < arr.length; i++) {
    	 
    	 if(arr[i] - arr[i-1] > 1) {
			sb.append(start);
			if (start != end) {
				sb.append("-").append(end);
			}
			sb.append(",");
			start = arr[i];
    	 }
    	 
    	 end = arr[i];
    	}
    	
    	sb.append(start);
    	if (start != end) {
    		sb.append("-").append(end);
    	}
    			
    	return sb.toString();
    
    }

- Vj August 06, 2022 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

lksa;ldkas;

- Vj August 06, 2022 | 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