Directi Interview Question for Interns


Country: India




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

{import java.util.HashMap;


public class careercup {
	public static void main(String args[])
	{
		HashMap<String, HashMap<String, String>> obj = new HashMap<String, HashMap<String, String>>();
		input_prop("tree","one:1,two:2,four:4",obj);
		input_prop("woods","one:2,two:2,three:5,four:4",obj);
		input_prop("leaves","one:1,two:2,three:8,four:4",obj);
		input_prop("fruits","one:1,three:9,four:4",obj);
		check(obj,"one:1,four:4");
		/*check(obj,"two:2,four:4");
		check(obj,"three:3,four:4");
		*/
		
	}
	public static void input_prop(String obj_name, String prop, HashMap<String, HashMap<String, String>> obj1)
	{
		String properties[] = prop.split(",");
		HashMap<String, String> prop_map = new HashMap<String, String>();
		for(int i=0;i<properties.length;i++)
		{
			prop_map.put(properties[i].split(":")[0], properties[i].split(":")[1]);
		}
		obj1.put(obj_name, prop_map);
	}
	public static void check(HashMap<String, HashMap<String, String>> data, String items)
	{
		String output="";	
		boolean flg = false;
		String query[]=items.split(",");
		HashMap<String, String> query_final=new HashMap<String, String>();
		for(int i=0;i<query.length;i++)
		{
			query_final.put(query[i].split(":")[0], query[i].split(":")[1]);
		}
		
		for(String keys:data.keySet())
		{
			HashMap<String,String> values = data.get(keys);
			for(String qry_fnl:query_final.keySet())
			{
				if(values.containsKey(qry_fnl) && values.containsValue(query_final.get(qry_fnl)))
						{
						flg=true;
						}
				else
					{flg=false;
					break;}
				
			}
			if(flg==true)
			output=output + " "+keys;
		}
		
		System.out.println("Output"+output);
	}
}

}

- shah.naiya8291 November 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If the property keys are strings, you could consider using a trie for them.

- chink November 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<bits/stdc++.h>
#include<set>
#include<string.h>
#include<vector>
#include<hash_map>
#define ll long long int
#define sd1(a) scanf("%d",&a)
#define sd2(a,b) scanf("%d %d",&a,&b)
#define sd3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define slld1(a) scanf("%lld",&a)
#define slld2(a,b) scanf("%lld %lld",&a,&b)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loope(i,a,b) for(int i=a;i<=b;i++)
#define loopd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int main()
{
int i,j,k,n,m;
string key,val;
sd2(n,m);
vector< set< pair<string, string> > > ma;
set< pair<string, string> >::iterator it;
for(i=0;i<n;i++)
{
sd1(k);
set< pair<string,string> > a;
while(k--)
{
cin>>key>>val;
pair<string, string> temp;
temp.first = key;
temp.second = val;
a.insert(temp);
}
ma.push_back(a);
}
for(i=0;i<m;i++)
{
sd1(k);
vector< pair<string,string> > q;
pair<string,string> temp;
for(i=0;i<k;i++)
{
cin>>key>>val;
temp.first = key;
temp.second = val;
q.push_back(temp);
}
bool b=false;
int c=0;
for(i=0;i<n;i++)
{
b=false;
for(j=0;j<k;j++)
{
it = ma[i].find(q[j]);
if(it != ma[i].end())
b=true;
else
{
b=false;
break;
}
}
if(b)
c++;
}
printf("%d\n",c);
}
}

- shuvambosana0705 August 21, 2015 | 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