First Orion Interview Question for SDE1s


Country: United States




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

#include <iostream>
#include <string>
using namespace std;
static int count=0;
void interceptCounter(string &a, string &b){

for (int i = 0; i<a.length(); i++){
for(int z=0; z<b.length(); z++){
if( a[i]==b[z]){
++count;

cout<<"The "<<i+1<<"th value of a intercepts with the "<<z+1<<"th value of b\n";
// if you want to do a switch case for the th,nd, and st of the worlds suit thyself.
}
}
}
cout<<"There are "<<count<<" interceptions"<<endl;


}

int main() {
string err= "thessalonians";
string merr = "collosians";
interceptCounter(err, merr);



return 0;
}

- Mobolaji January 07, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i guess hashmap for bigger word would help here where key will be the char of words and value will be no. of occ of the char. and for second word simply search in the map and add up all the value

- harry July 07, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class WordIntersections
{

	private Map<Character, List<Integer>> toMap(String word)
	{
		Map<Character, List<Integer>> map = new HashMap<>();
		for (int index = 0; index < word.length(); index++)
		{
			map.computeIfAbsent(word.charAt(index), k -> new ArrayList<Integer>()).add(index);
		}
		return map;
	}

	private String position(int n)
	{
		int num = n + 1;
		String str = String.valueOf(num);
		switch (str.charAt(str.length() - 1))
		{
			case '1':
				return num + "st";
			case '2':
				return num + "nd";
			case '3':
				return num + "rd";
			default:
				return num + "th";
		}
	}

	public List<String> getIntersections(String word1, String word2)
	{
		List<String> intersections = new ArrayList<>();
		Map<Character, List<Integer>> map = toMap(word2);
		for (int index = 0; index < word1.length(); index++)
		{
			List<Integer> integers = map.get(word1.charAt(index));
			if (integers != null)
			{
				for (Integer i : integers)
				{
					intersections
					        .add("The " + position(index) + " letter of " + word1 + " intersects with " + position(i) + " letter of " + word2 + ".");
				}
			}
		}
		return intersections;
	}
}

- gregrode July 11, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>
#include <string>
using namespace std;
static int count=0;
void interceptCounter(string &a, string &b){

for (int i = 0; i<a.length(); i++){
for(int z=0; z<b.length(); z++){
if( a[i]==b[z]){
++count;

cout<<"The "<<i+1<<"th value of a intercepts with the "<<z+1<<"th value of b\n";
}
}
}
cout<<"There are "<<count<<" interceptions"<<endl;


}

int main() {
string err= "thessalonians";
string merr = "collosians";
interceptCounter(err, merr);


// your code goes here
return 0;
}

- princemoronfolu January 07, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def intersect(s1, s2):
	intersection = []
	for char in set(s1):
		intersection.extend(char * min(s1.count(char), s2.count(char)))
	#return intersection if you want to see characters
	return Len(intersection)
#Test program
print(intersect("sales", "isles")
#prints 4

- seneza.gaston@philander.edu February 14, 2020 | 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