Interview Question for Software Engineer / Developers


Country: United States




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

select userid, count(userid) as num
from table
group by userid
order by num desc limit 1

- Anonymous October 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

SELECT user FROM Table GROUP BY user HAVING COUNT(user) = (SELECT COUNT(user) FROM Table GROUP BY user ORDER BY COUNT(user) DESC LIMIT 1)

- andycuisong September 17, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Good answer, but this doesn't work in Oracle.
Need to use "where ROWNUM=1" in Oracle instead of "limit 1".

I think this will work:
SELECT user FROM Table GROUP BY user HAVING COUNT(user) =
(SELECT max(c) FROM (SELECT COUNT(user) c FROM Table GROUP BY user))

- jwei.aiesec.tju September 25, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I use mySQL so the syntax is a little bit different. Thanks for pointing out.

- andycuisong October 01, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

SELECT USER
FROM
(SELECT USER,COUNT(1) AS TotalLogins FROM TABLE GROUP BY USER
)
WHERE rownum = 1
ORDER BY TotalLogins DESC;

- PKT October 03, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

The question hinted that the user id is not a unique field. I will do it this way

select t.uid, max(t.countUid)
from
(select uid, count(uid) as countUid from yourtable group by uid order by countUid desc) t

- trythis September 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

;with ctegtloginattempt
as
(select
DENSE_RANK() over (partition by userid order by loggedintime) as loginattempts, userid
from useridlogintbl
)

select userid, max(loginattempts) as loginattempts from ctegtloginattempt
group by userid
order by loginattempts desc

- Niraj September 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select * ,count(ids) from logins group by ids;

- Neeraj September 27, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

SELECT count(date), id FROM user GROUP BY user.id ORDER BY date ASC LIMIT 1;

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

SELECT count(date), id
FROM user
GROUP BY user.id
ORDER BY date ASC
LIMIT 1;

- samruddhi.m.suryaji November 03, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select top 1 userid from (
select userid,count(date)count
from table
group by userid)c
order by COUNT desc

- Deepthi January 26, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select * from (select userid,count(*) from table group by userid ) where rownum=1;

- kranti Ingale November 14, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select user_id, count(user_id) from user_table group by user_id order by count(user_id) DESC limit 1;

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

select user_id, count(user_id) from user_table group by user_id order by count(user_id) DESC limit 1;

- raisa April 19, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Select user, max(log_count) from (Select count(date) AS log_count, user_id AS user from table group by user_id) ;

- Greg September 04, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

#include<iostream>
using namespace std;
int sort(int arr[],int l);
int main()
{
	int arr[10] = {3,6,2,1,0,5,7,8,3,4};
	int arr2[10]= {4,1,6,3,8,10,11,5,9,2};
	sort(arr,10);
	sort(arr2,10);
	int j=0;
	for(int i=0;i<10;i++)
	{
		while(arr[i]>arr2[j])
		{
			cout<<"("<<arr[i]<<","<<arr2[j]<<")";
			j++;
		}
	}
}

int sort(int arr[],int l)
{
 int min;
 int k=0;
 for(int i=0;i<l;i++)
 {
 	min =arr[i];
 	for(int j=i;j<l;j++)
 	{
 		if(min > arr[j])
 		{
 			min = arr[j];
 			k=j;
 		}
 	}
 	arr[k] =arr[i];
 	arr[i] = min;
 }
}

- Anonymous September 04, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

If this is a SQL question, it's pretty straight forward. The below returns a sorted list with the most logins at the top. If you need only to return a single row, simply turn this into a sub-query and select user_id from sub-query where rownum = 1.

select
user_id
,count(date) as logins

from table_name

group by
user_id

order by count(date) desc

- masterjaso September 04, 2014 | 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