0% found this document useful (0 votes)
417 views

Java Interview Questions

This document contains questions and problems related to coding and algorithms: 1) A query to rank order a table by votes and display the rank. 2) A function to capitalize the first letter of each word in a string. 3) A procedure to split a column into rows using a delimiter. 4) A SQL query to count the number of bugs open within a date range from a bugs table. 5) An efficient algorithm to check if a string is a palindrome. 6) An efficient algorithm to find complementary pairs in an array of integers. 7) A way to find the top 10,000 most frequent phrases from a large file that does not fit in

Uploaded by

struta.cristian
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
417 views

Java Interview Questions

This document contains questions and problems related to coding and algorithms: 1) A query to rank order a table by votes and display the rank. 2) A function to capitalize the first letter of each word in a string. 3) A procedure to split a column into rows using a delimiter. 4) A SQL query to count the number of bugs open within a date range from a bugs table. 5) An efficient algorithm to check if a string is a palindrome. 6) An efficient algorithm to find complementary pairs in an array of integers. 7) A way to find the top 10,000 most frequent phrases from a large file that does not fit in

Uploaded by

struta.cristian
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

WalletHub.

com
Please make sure that you test your code before you
submit it to us. For correct answers we will also be
grading the code efciency. Even if you can't answer a
question we would like to know your a!!roach on how
you would solve the !roblem.
"y#$%
1) Write a query to rank order the following table in MySQL by votes, display the
rank as one of the coluns!
&'E()E )(*%E votes + name &H('+,-. votes /0) .1
/0#E') /0)2 votes 3(%4E#
+'#mith',-. +'5ones',6. +'White'7-. +'*lack'8-. +'9reen'6-.
+'*rown'7-.1
SET @rank=0;
SELECT name, votes, @rank:=@rank+1 AS rank2
FROM votes
ORDER ! votes DESC;
") Write a function to capitali#e the $rst letter of a word in a
given string%
&'aple( initcap)*+,-&. states /f 0&1,ca ) 2 *nited States /f
0erica
31&0-& 4*+3-,/+ 3apitali#e )string5phase 6013701)"88))
1&-*1+S 6013701)"88)
9&:,+
.&3L01& len ,+-%
.&3L01& i ,+-%
S&- len 2 37015L&+:-7)string5phase)%
S&- string5phase 2 L/W&1)string5phase)%
S&- i 2 ;%
W7,L& )i < len) ./
,4 )M,.)string5phase,i,1) 2 = = /1 i 2 ;) -7&+
,4 )i < len) -7&+
S&- string5phase 2 3/+30-)
L&4-)string5phase,i),
*>>&1)M,.)string5phase,i ? 1,1)),
1,:7-)string5phase,len @ i @ 1)
)%
&+. ,4%
&+. ,4%
S&- i 2 i ? 1%
&+. W7,L&%
1&-*1+ string5phase%
&+.%
A) Write a procedure in MySQL to split a colun into rows using a
deliiter!
&'E()E )(*%E sometbl + /: /0) 0("E 3('&H('+6-. .1
/0#E') /0)2 sometbl 3(%4E# +, '#mith'. +7 '5ulio;
5ones;Falcons'. +< 'White;#now'. +8 'Paint;/t;'ed'. +6
'9reen;%antern'. += '*rown;bag'.1
4or )"), e'aple rows would look like BB CA, whiteD, CA, SnowD
E
F) , have a table for bugs fro a bug tracking software% letGs call
the table CbugsD! -he table has four coluns )id, open5date,
close5date, severity)! /n any given day a bug is open if the
open5date is on or before that day and close5date is after that
day! 4or e'aple, a bug is open on C";1"@;1@;1D, if itGs created
on or before C";1"@;1@;1D and closed on or after C";1"@;1@;"D! ,
want a SQL to show nuber of bugs open for a range of
dates!
Select count)H) if open5date<2D";1"@;1@;1D and close5date B2D";1"@;1@
;"D
5(3(
1) Write an eIcient algorith to check if a string is a palindroe!
0 string is a palindroe if the string atches the reverse of
string!
&'aple( 1""1 is a palindroe but not 11"1!
!ackage test%
!ublic class -est4acebook J
!ublic static void ain)StringKL args) J
String palindroe 2 MababasM%
charKL string5line 2 palindroe!to3har0rray))%
Syste!out!println)functionPalindrom)string5line))%
N
!ublic static boolean function>alindro)charKL palindroe)J
boolean boolean5palindro 2 false%
if)palindroe!lengthO" 22 ;)J
for)int i 2 ;% i < palindroe!lengthP"@1% i??)J
if)palindroeKiL Q2 palindroeKpalindroe!length@i@1L)J
return false%
NelseJ
boolean5palindro 2 true%
N
N
NelseJ
for)int i 2 ;% i < )palindroe!length@1)P"@1% i??)J
if)palindroeKiL Q2 palindroeKpalindroe!length@i@1L)J
return false%
NelseJ
boolean5palindro 2 true%
N
N
N
return boolean5palindro%
N
N
") Write an eIcient algorith to $nd R@copleentary pairs in a
given array of integers! :iven 0rray 0, pair )i, S) is R@
copleentary if R 2 0KiL ? 0KSL%
A) :iven a large $le that does not $t in eory )say 1;:9), $nd
the top 1;;;;; ost frequent phrases! -he $le has 8; phrases
per line separated by a pipe )T)! 0ssue that the phrases do
not contain pipe!
&'aple line ay look like( 4oobar 3andy T /lypics ";1" T
>:0 T 3+&- T Microsoft 9ing E!
-he above line has 8 phrases in visible region!

You might also like