Interview Question for Software Engineer / Developers

Country: United States
Interview Type: In-Person

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

Each prisoner`s rank can be represented by a node and his friends can be depicted by adjoining nodes.

hashmap with key=prisoner : value = Danger rank
for each node hashmap[prisoner]= rank + rank of directly connected nodes

return hashmap

Now this will work only if graph is connected, which if we take kevin bacon`s consideration, every prisoner should be connected to every prisoner

- abhinav bansal February 12, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

#include <iostream>
#include <vector>
#include <utility>
#include <string>

using namespace std;

class prison{

	int rank;
	string name;
	int totalrank;
	std::vector<prison> friends;
	void compute_rank();
	prison(std::string name,int,std::vector<prison>);
	inline std::string getName(){return this->name;}
	inline int getRank(){return this->rank;}
	inline int getTotal(){return this->totalrank;}
	inline std::vector<prison> getFriends(){return this->friends;}
	void print();
prison::prison(std::string name,int rank,std::vector<prison> friends){
	this->name = name;
	this->friends = friends;
	this->rank = rank;
void prison::print(){
	cout<<"Prisoner Name: "<<this->name<<" Rank: "<< this->rank<<endl;
	cout<<"Prisoner Friends: \n"<<"Name\tRank: "<<endl;
	for(auto f : this->friends){
		cout<<<<"\t"<< f.rank<<endl;

void prison::compute_rank(){
	this->totalrank = this->rank;
	for(auto e : friends){

void find_most_dangerous(std::vector<prison> p){
	std::pair<int,std::string> mdp;
	mdp = make_pair(p[0].getTotal(), p[0].getName());
	for(auto e : p){
		if(e.getTotal() > mdp.first){
			mdp = make_pair(e.getTotal(),e.getName()); 
	cout<<"Most Dangerous prisoner: " << mdp.second << " rank : "<<mdp.first<<endl;

int main(){
	std::vector<prison> b;
	prison a("A", 21, b);
	prison c("B", 44, b);
	prison d("D", 10, b);
	prison ds("DS", 10, b);
	for(auto f : b){
	return 0;


- Tinashe February 12, 2015 | Flag Reply

Add a Comment

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


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


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