Showing posts with label interview questions. Show all posts
Showing posts with label interview questions. Show all posts

27.7.10

got balls ?? SOLVE this simple puzzle

Many hundreds of years ago in a small Italian town, a merchant had the misfortune of owing a large sum of money to the moneylender. The moneylender, who was old and ugly, fancied the merchant's beautiful daughter so he proposed a bargain. He said he would forgo the merchant's debt if he could marry the daughter. Both the merchant and his daughter were horrified by the proposal.

The moneylender told them that he would put a black pebble and a white pebble into an empty bag. The girl would then have to pick one pebble from the bag. If she picked the black pebble, she would become the moneylender's wife and her father's debt would be forgiven. If she picked the white pebble she need not marry him and her father's debt would still be forgiven. But if she refused to pick a pebble, her father would be thrown into jail.

They were standing on a pebble strewn path in the merchant's garden. As they talked, the moneylender bent over to pick up two pebbles. As he picked them up, the sharp-eyed girl noticed that he had picked up two black pebbles and put them into the bag. He then asked the girl to pick her pebble from the bag.

What would you have done if you were the girl? If you had to advise her, what would you have told her? Careful analysis would produce three possibilities:

1. The girl should refuse to take a pebble.
2. The girl should show that there were two black pebbles in the bag and expose the moneylender as a cheat.
3. The girl should pick a black pebble and sacrifice herself in order to save her father from his debt and imprisonment.

Solve & mail me the answer.
Hint: The girl does nothing from the above 3 given options. But then too she saves her father of the debt AND also saves herself out of the marriage trap.

30.4.10

Witty Interview Questions

Q. How can you drop a raw egg onto a concrete floor without cracking it?

Q. If it took eight men ten hours to build a wall, how long would it take four men to build it?

Q. If you had three apples and four oranges in one hand and four apples and three oranges in the other hand, what would you have?

Q. How can you lift an elephant with one hand?

Q. How can a man go eight days without sleep?

Q. If you throw a red stone into the blue sea what it will become?

Q. What looks like half apple ?

Q. What can you never eat for breakfast ?

Q. Bay of Bengal is in which state?

Next Question :
You are driving along in your car on a wild, stormy night, it's raining heavily, when suddenly you pass by a bus stop, and you see three people waiting for a bus:

An old lady who looks as if she is about to die.
An old friend who once saved your life.
The perfect partner you have been dreaming about.

Which one would you choose to offer a ride to, knowing very well that there could only be one passenger in your car?

An HR Question:
What will you do if I run away with your sister?"

Question to a unmarried student girl candidate:
What if one morning you woke up & found that you were pregnant.

Question:
I ordered a cup of coffee for the candidate. Coffee arrived kept before the candidate, then I ask that what is before you?

Question:
This is your last question of the interview. What came first egg or hen?

Mail me at CrazyEmperor.com@gmail.com to know the answers.

18.7.09

faadu interview Logical Aptitude puzzle questions here..... anyone there !!

Part 1:
  1. You have to get from point A to point B. You don’t know if you can get there. What would you do?
  2. Imagine you have a closet full of shirts. It’s very hard to find a shirt. So what can you do to organize your shirts for easy retrieval?
  3. What method would you use to look up a word in a dictionary?
  4. Every man in a village of 100 married couples has cheated on his wife. Every wife in the village instantly knows when a man other than her husband has cheated, but does not know when her own husband has. The village has a law that does not allow for adultery. Any wife who can prove that her husband is unfaithful must kill him that very day. The women of the village would never disobey this law. One day, the queen of the village visits and announce that at least one husband has been unfaithful. How many husbands get killed; if any; & in how many days ??
  5. Mike has $20 more than Todd. How much does each have given that combined they have $21 between them. You can’t use fractions in the answer.
  6. How do you cut a rectangular cake into two equal pieces when someone has already taken a rectangular piece from it? The removed piece an be any size or at any place in the cake. You are only allowed one straight cut.
  7. How many piano tuners are there in the entire world?
  8. Two MIT math graduates bump into each other. They hadn’t seen each other in over 20 years.The first grad says to the second: “how have you been?” Second: “Great! I got married and I have three daughters now” First: “Really? how old are they?” Second: “Well, the product of their ages is 72, and the sum of their ages is the same as the number on that building over there..” First: “Right, ok.. oh wait.. I still don’t know” second: “Oh sorry, the oldest one just started to play the piano”First: “Wonderful! my oldest is the same age!” So, how old are the daughters?
  9. What gives you joy?
  10. Four people need to cross a rickety rope bridge to get back to their camp at night. Unfortunately, they only have one flashlight and it only has enough light left for seventeen minutes. The bridge is too dangerous to cross without a flashlight, and it’s only strong enough to support two people at any given time. Each of the campers walks at a different speed. One can cross the bridge in 1 minute, another in 2 minutes, the third in 5 minutes, and the slow poke takes 10 minutes to cross. How do the campers make it across in 17 minutes?
  11. If the probability of observing a car in 30 minutes on a highway is 0.95, what is the probability of observing a car in 10 minutes (assuming constant default probability)?
  12. In a country in which people only want boys, every family continues to have children until they have a boy. if they have a girl, they have another child. if they have a boy, they stop. what is the proportion of boys to girls in the country?
  13. You have an empty room, and a group of people waiting outside the room. At each step, you may either get one person into the room, or get one out. Can you make subsequent steps, so that every possible combination of people is achieved exactly once?
  14. You are at a party with a friend and 10 people are present including you and the friend. your friend makes you a wager that for every person you find that has the same birthday as you, you get $1; for every person he finds that does not have the same birthday as you, he gets $2. would you accept the wager?
  15. How many golf balls can fit in a school bus?
  16. You are shrunk to the height of a nickel and your mass is proportionally reduced so as to maintain your original density. You are then thrown into an empty glass blender. The blades will start moving in 60 seconds. What do you do?
  17. How much should you charge to wash all the windows in Seattle?
  18. How would you find out if a machine’s stack grows up or down in memory?
  19. Explain a database in three words to your eight-year-old nephew.
  20. You have five pirates, ranked from 5 to 1 in descending order. The top pirate has the right to propose how 100 gold coins should be divided among them. But the others get to vote on his plan, and if fewer than half agree with him, he gets killed. How should he allocate the gold in order to maximize his share but live to enjoy it?
  21. In a country in which people only want boys, every family continues to have children until they have a boy. if they have a girl, they have another child. if they have a boy, they stop. what is the proportion of boys to girls in the country?
Part 2:
1)
A king knows he's going to die and decides to leave all his wealth to the most intelligent of his three sons. So he tells them that he's going to put them through a test, and the first person to give the correct answer would get it all.

He tells his sons:

1. I'll seat the three of you in a room such that each person can see the other.

2. On each of your heads, I'll put a cap, the colour of which will be either blue or black...each person will be able to see the colour of the cap on the other two people, but will obviously not be able see the colour of the cap on his own head.

3. The moment someone sees 2 black caps and 2 black caps only, he raises his hand to give a signal.

4. You have to correctly work out the colour of the cap on your own head.

So saying, he seats them in the room and puts a blue cap on each one's head. Naturally, no one gives a signal because no one can see two black caps (each can see two blue caps on the others' heads obviously). However, after a couple of minutes, the most intelligent son correctly says that a blue cap is on his head and thus gets all the wealth.

Question: How does he work it out??

2)

A king is about to have a celebration tommorrow. The celebration is the most important party he has ever hosted. He has got 1000 bottles of wine for the celebration, but he has just got to know that one of them is poisoned.

The poison exhibits no symptoms until death. Death occurs within ten to twenty hours after consuming even the minutest amount of poison. The king has just 10 prisoners at his disposal (to sacrifice if need be) and just under 24 hours to determine which single bottle is poisoned. How does the king find the poisoned bottle by using just these 10 prisoners?

3)
A mad king tells his 100 wisest men he is about to line them up and place either a red or blue hat on each head. Once lined up, they must not communicate amongst themselves nor attempt to look behind them nor remove their own hat.

The king tells the wise men that they will be able to see all the hats in front of them. They will not be able to see the color of their own hat or the hats behind them, although they will be able to hear the answers from all those behind them.

The king will then start with the wise man in the back and ask "what color is your hat?" The wise man will only be allowed to answer "red" or "blue," nothing more. If the answer is incorrect then the wise man will be silently killed. If the answer is correct then the wise man may live but must remain absolutely silent.

The king will then move on to the next wise man and repeat the question.

Before they are lined up, the king makes it clear that if anyone breaks the rules then all the wise men will die. The king listens in while the wise men consult each other to make sure they don't devise a plan to communicate anything more than their guess of red or blue.

The wise men devise a method in which a maximum on only 1 wise man need be killed. What method do they use?

4)
1000 people are standing in a circle...the first person has a gun.he kills the person next to him and passes the gun to the third person. The third person kills the person next to him and hands over the gun to the fifth person. This continues until there is just one person left alive
who will be the last person left alive..??

5)
A jail warden meets with 23 new prisoners when they arrive and tells them, "You may meet today and plan a strategy. But after today, you will be in isolated cells and will have no communication with one another."

"In the prison is a switch room, which contains two light switches labeled 1 and 2, each of which can be in either up or the down position. I am not telling you their present positions. The switches are currently not connected to anything."

"After today, from time to time, I will select one prisoner at random and escort him to the switch room. This prisoner will select one of the two switches and reverse its position. He must flip one switch when he visits the switch room, and may only flip one of the switches. Then he'll be led back to his cell."

"No one else will be allowed to alter the switches until I lead the next prisoner into the switch room. I'm going to choose prisoners at random. I may choose the same guy three times in a row, or I may jump around and come back. I will not touch the switches myself."

"Given enough time, everyone will eventually visit the switch room the same number of times as everyone else. At any time, anyone may declare to me, 'We have all visited the switch room.'"

"If it is true, then you will all be set free. If it is false, and somebody has not yet visited the switch room, you will all die horribly. You will be carefully monitored, and any attempt to break any of these rules will result in instant death to all of you"

What is the strategy they come up with so that they can be free?

***** mail me at CrazyEmperor.com@gmail.com for the answers *****

1.5.09

LAMP / WAMP interview questions. Have Guts ?? Answer them !

1) what are practical uses of References in PHP ??

2) What is the best technique or tool that can migrate data residing in a MS SQL Server database or Oracle database to a MySQL databaase ??

3) how to count number of simultaneous users on a web page and how to restrict more than a particular number of users ??

4) "Safe Mode" been disabled in PHP 6. What disadvantages did it pose that Zend had to take such a step ??

5) What is difference between Server-side-Ajax-frameworks (like Sajax, Xajax) and Browser-side-Ajax-frameworks (like AjaxLib, SACK) ??

6) What is the advantage of compiling PHP with the optin "--disable-all" ??

7) Why are following PHP extensions called "Self Contained" : MySQL, LDAP, DBA, PCRE, GD, CURL ??

8) What is meant by saying : "Base PHP package depends only on XML parser" ??

9) Is XML compulsory in Ajax implementation ??

10) List all advantages that CURL has over fopen ??

11) which one is safer (or can be made safe) : GET or POST ??

12) What is the importance of Headers ??

23.6.08

Answer these PHP interview questions ..... anyone there ?? have GUTS ??

1) why is safe mode needed in php ?? what is safe mode?? explain shared-server-security problem ??
2) How to simulate a destructor; supported in PHP 5; in PHP 4 ??
3) how will you expire a user's sesion if he remains inactive for 10 mins - cokkies are turned off on browser - DO not say that you will delete all session files after 10 minutes , because then all active/inactive users will be signed out after 10 mins :)
4) What is the relation between pattern and framework in php ??
5) how to find how many users are active on mysite at any moment ??.... and how to restrict only 50 users to access my php page from server ??
6) how does a load balancer sitting on top of a web server function ??
7) Does PHP 5 supports Method overloading in the same way java does ??.... if not why not ??....and how can it be made to ??
8) how can you emulate php 5's function _construct in PHP 4 ??
9) In what all cases is manually freeing of memory required in PHP ??
10) is a LAMP website example of a 2-tier-architecture or 3-tier-architecture ?? HOW ??
11) Tell differences between Cron and a Service ?? Also tell the similarities ??
12) Why is HTML not called a server-side language even when it can interact with server using GET and POST ??

9.5.08

PHP interview question

Is it possible to set a time expire page in PHP.?
header("Expires: Mon, 26 Jul 2007 05:00:00 GMT");
?>


How can we save an image from a remote web server to my web server using PHP?
$file_rimg = fopen("http://w3answers /image23.jpg",'rb');
$newfile_name_img = "/tmp/tutorial.file";
$file_wnew = fopen($newfile_name_img,'wb');
while (!feof($file_rimg)) {
$chunk_rd = fread($file_rimg,1024);
fwrite($file_wnew,$chunk_rd);
}
fclose($file_wnew);
fclose(file_rimg);
?>


What is the output of 2^2 in php?
The answer is 0 (Zero)
Everyone expected answer would be 4.But answer is zero.
The ^ operator is different in each language.In PHP ^
means the bitwise exlusive or of the two numbers.

Output of this script ??

$x = 3;
switch ($x) {
case 2: echo 'line 1'; break;
case 3:
case 4: echo 'line 2'; break;
default: echo 'line 3';
}
?>

a. echo 'line 3';
b. echo 'line 2';
c. Error
d. None of the above

Ans: b (Answer is line2)


Output of this script ??

$list = array("clock","scissors","pen","yak");
$list[] = "cow";
$list[] = "dragon";
print "$list[4]";
?>

a. Error
b. cow
c. yak
d. nothing

ANS: b (cow)


Output of this script ??

echo 5+FALSE;
?>

a. 5
b. nothing
c. parse error
d. T_ECHO error

ANS: 5


Output of this script ??

$x = '';
switch ($x) {
case "0": echo "String"; break;
case 0: echo "Integer"; break;
case NULL: echo "NULL"; break;
case FALSE: echo "Boolean"; break;
case "": echo "Empty string"; break;
default: echo "Something else"; break;
}
?>

a. Something else
b. Empty string
c. Integer
d. String


ANS: Integer

Output of this script ??

function x ($y)
{

function y ($z)
{

return ($z*2);
}

return($y+3);
}

$y = 4;
$y = x($y)*y($y);
echo "$y";
?>

a. None
b. 55
c. 56
d. 57

ANS:56


Which function will give a list of system specific hashing algorithms that are supported by php ?
use the following funcion: hash_algos()
This function is only available in php 5.1.2 and above


What changes you will have to do in php.ini file for file uploading?
do the following line uncomment:
; Whether to allow HTTP file uploads.
file_uploads = On
; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
upload_tmp_dir = C:\apache2triad\temp
; Maximum allowed size for uploaded files.
upload_max_filesize = 2M


How can you get round the stateless nature of HTTP using PHP?

The top Most important techniques are sessions and cookies. To access a session, you will need to have session_start() at the top of each page (if you are getting errors while you use in other places of the page.put ob_start() after ), and then you will use the $_SESSION hash to access and store your session variables. For cookies, You must use the set_cookie function before any output is started in your PHP script. From then on you can use the $_COOKIE has to access your cookie variables and values.

Important:
HTTP is a stateless protocol. The advantage of a stateless protocol is that hosts do not need to retain information about users between requests, but this forces web developers to use alternative methods for maintaining users' states. For example, when a host would like to customize content for a user while visiting a website, the web application must be written to track the user's progress from page to page. A common method for solving this problem involves sending and requesting cookies. Other methods include server side sessions, hidden variables (when current page is a form), and URL encoded parameters (such as /index.php?session_id=some_unique_session_code).

What is CAPTCHA?

CAPTCHA stands for Completely Automated Public Turing Test to tell Computers and Humans Apart. To prevent spammers from using bots to automatically fill out forms, CAPTCHA programmers will generate an image containing distorted images of a string of numbers and letters. Computers cannot determine what the numbers and letters are from the image but humans have great pattern recognition abilities and will be able to fairly accurately determine the string of numbers and letters. By entering the numbers and letters from the image in the validation field, the application can be fairly assured that there is a human client using it. To read more look here:
http://en.wikipedia.org/wiki/Captcha


What is difference between require_once(), require(), include().?

Difference between require() and require_once(): require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page). So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example. This way you make sure you don't include the file more times and you will not get the "function re-declared" error. Difference between require() and include() is that require() produces a FATAL ERROR if the file you want to include is not found, while include() only produces a WARNING. There is also include_once() which is the same as include(), but the difference between them is the same as the difference between require() and require_once().

If you have to work with dates in the following format: "Tuesday, February 14, 2006 @ 10:39 am", how can you convert them to another format, that is easier to use?

The strtotime function can convert a string to a timestamp. A timestamp can be converted to date format. So it is best to store the dates as timestamp in the database, and just output them in the format you like.


So let's say we have
$date = "Tuesday, February 14, 2006 @ 10:39 am";
In order to convert that to a timestamp, we need to get rid of the "@" sign, and we can use the remaining string as a parameter for the strtotime function.

So we have
$date = str_replace("@ ","",$date);
$date = strtotime($date);

now $date is a timestamp
and we can say:
echo date("d M Y",$date);

How we know browser properties?

get_browser() attempts to determine the capabilities of the user's browser. This is done by looking up the browser's information in the browscap.ini file.
echo $_SERVER['HTTP_USER_AGENT'] . "\n";
$browser = get_browser();
foreach ($browser as $name => $value)
{
echo "$name $value\n";
}

How i will check that user is, logged in or not. i want to make it a function and i want to use in each page and after login i want to go in current page(same page. where i was working)?

For this we can use the session objec($_SESSION)t. When the user login with his/ her user name and password, usually we check those to ensure for correctness. If that user name and password are valid one then we can store that user name in a session and then we can very that session variable has been set or not in a single files and we can include that file in all pages.


How i can get ip address?

We can use SERVER var $_SERVER['SERVER_ADDR'] and getenv("REMOTE_ADDR") functions to get the IP address.


What is differenc between mysql_connect and mysql_pconnec?

mysql_pconnect establishes a persistent connection. If you don't need one (such as a website that is mostly HTML files or PHP files that don't call the db) then you don't need to use it. mysql_connect establishes a connection for the duration of the script that access the db. Once the script has finished executing it closes the connection. The only time you need to close the connection manually is if you jump out of the script for any reason.

If you do use mysql_pconnect. You only need to call it once for the session. That's the beauty of it. It will hold open a connection to the db that you can use over and over again simply by calling the resource ID whenever you need to interact with the db.


What is the difference between echo and print statement?

There is a slight difference between print and echo which would depend on how you want to use the outcome. Using the print method can return a true/false value. This may be helpful during a script execution of somesort. Echo does not return a value, but has been considered as a faster executed command. All this can get into a rather complicated discussion, so for now, you can just use whichever one you prefer.


How to make a download page in own site, which i can know that how many file has been loaded by particular user or particular ipaddress?

We can use hyperlink having URL where file are kept. and we only allow regisetered user to download. from session of user we can get the user detail.

What are the Technology to Use for Parsing the XML ?

There are two types of XML parsers the we can use.
1. DOM (Document Object Module).
2. SAX (Simple API for XML).

DOM

The DOM (Document Object Model) extension allows to operate on XML documents through the DOM API with PHP 5. DOM is a standard defined by the W3C for accessing XML documents.

In PHP 4, DOM xml extension is not following the standard method names.

As per the new W3C compatibility, the old domxml-based scripts won't work anymore. The API is quite different in PHP 5. But if we used the "almost W3C compatible" method names available in PHP 4.3, We only need to change the loading and saving methods, and remove the underscore in the method names. Other adjustments here and there may be necessary, but the main logic can stay the same. Though we have not used earlier so these will not be a problem for us.

The easiest way to read a well-formed XML file is to use the DOM library . The DOM library reads the entire XML document into an object and represents it as a tree of nodes,

SAX

SAX stands for Simple API for XML. It's a callback-based interface for parsing XML documents. SAX support has been available since PHP 3 and hasn't changed a lot since then. For PHP 5 the API is unchanged, The only difference is that it's not based on the expat library anymore, but on the libxml2 library.

Rather than treating an XML document as a tree-like structure, SAX treats it as a series of events such as startDocument or endElement. To accomplish this, a SAX appllication consists of a parser that sends these events to "handlers," methods or functions designated to handle them.

If you need a superfast forward only XML parser, you can use XMLReader. However you probably don\'t want a forward only parser.

If you want to read data from an XML file, the simple XML extension is probably the nicest solution. Also for creating XML, it might work well for you. Have a look at this article: http://devzone.zend.com/node/view/id/688.

If you want a superfast forward only XML writer, use XMLWriter. You could also do this by just outputting the XML of sticking it all together in a string. But the XMLWriter will make your code clearer, automatically escape stuff and give some error indications.



How can we get second of the current time using date function?


what is Magic methods in php?

There are seven special methods, and they are as follows:

__construct( )
Called when instantiating an object

__destruct( )
Called when deleting an object

__get( )
Called when reading from a nonexistent property

__set( )
Called when writing to a nonexistent property

__call( )
Called when invoking a nonexistent method

__toString( )
Called when printing an object (for eg: converting an object to strings)

__clone( )
Called when cloning an object (copying object)

There are actually 12 special methods at last count
The function names __construct, __destruct (see Constructors and Destructors), __call, __get, __set, __isset, __unset (see Overloading), __sleep, __wakeup, __toString, __set_state and __clone

http://us2.php.net/oop5.magic


what is scandir() ?

List files and directories inside the specified path
By default files order will be ascending
$f = scandir($direct, 1); it will display the files as descending order


Which types of form elements can be excluded from the HTTP request?
A. text, radio, and check box
B. text, submit, and hidden
C. submit and hidden
D. radio and check box

Answer D is correct.

When not selected, both radio buttons and check boxes are excluded from the HTTP request. Answer A, C, B are incorrect because they are always included in the request.