Tuesday, December 4, 2007

Lehman Brothers FTA Technical and HR interview Experience

Technical (for about 50 min)

It started with some puzzles,

  1. Given 7 gold bars connected with ropes, you have to give a labour his payment for the day with one gold bar. You have to minimize the number of cuts (i.e. of ropes) so that you pay the labour for 7 days. He can never be under or over paid. <2>
  2. The next was the 4 persons crossing the bridge who take different times (10s, 5s, 2s, 1s)... they have to carry a lamp ..... only 2 persons can travel the bridge at a time. Optimize the total time required. You may wanna propose a general strategy to deal with n people all with different times.

Project related questions.

Internship related questions.

Computer Organization and Architecture related - how many functions did you implement in your 4 - bit CPU, name them. How many functions can be implemented, why the need for 0000 one. What is max bit size CPU available.

Cryptography - They asked about elliptic cryptography.

Sorting Related

Given two list of very large size (say 10 MB), how would you check that each element of one is present in the other. Start from the Brute force method, state its complexity. From here on start optimizing this check one step at a time, on the basis of Space and Time.

Knowledge of Sorting methods, their complexities, when and where will they be used.

Link List related

Reverse a single link list. Use minimum pointers. Do iteratively and also recursively, from front end and/or back end.

Given a pointer to an intermediate node of a link list whose head pointer we do not have, how would you delete it.

There were few other questions on linked list

Binary Tree Related

Questions related to tree heights , whats is the maximum and minimum height
of the tree. Write Mathematical expression for the height.

Write code to find the average height of the of the tree. Write code for finding maximum and minimum height of the tree.

Asked about other Search algorithms, other than binary Search.

There were some questions in between from other fields as well which I could no remember now. All these questions pretty much sums up the technical part.

Now the HR part .... (huff puff) (for about 20-25 min)

  1. Tell something about yourself.
  2. Tell about your family.
  3. Why not microsoft or google.
  4. Why Mumbai when you can work in Bangalore where your brother is.
  5. Where do you see yourself in 5 years.
  6. Why not research.
  7. What if you get a call from IIM A, B, C.
  8. What if you get a call from IIM L, K, I.
  9. Any Idea about firms like us (competitors).
  10. What do you expect from the company.
  11. How our Job profile different from others.
  12. Hows our company different from others.

There were other questions as well( i will post them when i remember ;-) ].

xoxo
aL











Sunday, December 2, 2007

How to display a percentage-done indication on the screen?

The character '\r' is a carriage return without the usual line feed, this helps to overwrite the current line. The character '\b' acts as a backspace, and will move the cursor one position to the left.

XOXO
aL

Sudoku verifier using bit fields

char VerifySudoku(char grid[81])
{
unsigned int bitFlags = 0;
unsigned short buffer; // to speed up things
char r, c;

for (r = 0; r < bitflags =" 0,">
{
for (c = 0; c <>
{
buffer = r/3*3+c/3;

// check horizontally
bitFlags |= 1 << (27-grid[(r<<3)+r+c])>
// check vertically
| 1 << (18-grid[(c<<3)+c+r])
// check subgrids

| 1 << (9-grid[(buffer<<3)+buffer+r%3*3+c%3]);
}
if (bitFlags != 0x7ffffff)
return 0;
}
return 1;
}

Dutch National Flag Algorithm, or 3-way Partitioning

The problem was posed with three colours, here `0', `1' and `2'. The array is divided into four sections:

  1. a[1..Lo-1] zeroes (red)
  2. a[Lo..Mid-] ones (white)
  3. a[Mid..Hi] unknown
  4. a[Hi+1..N] twos (blue)
The unknown region is shrunk while maintaining these conditions
  1. Lo := 1; Mid := 1; Hi := N;
  2. while Mid <= Hi do
    1. Invariant: a[1..Lo-1]=0 and a[Lo..Mid-1]=1 and a[Hi+1..N]=2; a[Mid..Hi] are unknown.
    2. case a[Mid] in
      • 0: swap a[Lo] and a[Mid]; Lo++; Mid++
      • 1: Mid++
      • 2: swap a[Mid] and a[Hi]; Hi--

XOXO
aL

Tuesday, September 25, 2007

Optimizing C and C++ Code

Optimizing C and C++ Code

Embedded software often runs on processors with limited computation power, thus optimizing the code becomes a necessity. In this article we will explore the following optimization techniques for C and C++ code developed for Real-time and Embedded Systems.

1. Adjust structure sizes to power of two
2. Place case labels in narrow range
3. Place frequent case labels first
4. Break big switch statements into nested switches
5. Minimize local variables
6. Declare local variables in the inner most scope
7. Reduce the number of parameters
8. Use references for parameter passing and return value for types bigger than 4 bytes
9. Don't define a return value if not used
10. Consider locality of reference for code and data
11. Prefer int over char and short
12. Define lightweight constructors
13. Prefer initialization over assignment
14. Use constructor initialization lists
15. Do not declare "just in case" virtual functions
16. In-line 1 to 3 line functions

Al

read more @ http://www.eventhelix.com/RealtimeMantra/Basics/OptimizingCAndCPPCode.htm#Place%20Frequent%20Case%20Labels%20First

Wednesday, September 5, 2007

Programming puzzles ... dare to solve

Programming puzzles ..... these are quite boring for the masters and experts , neways have a look at it ... i guess it will be fun for new experts .... and posts the answers as comments without checking out provided forum post.

Q1 Write a "Hello World" program in 'C' without using a semicolon.
Q2 Write a C++ program without using any loop (if, for, while etc) to
print numbers from 1 to 100 and 100 to 1;
Q3 C/C++ : Exchange two numbers without using a temporary variable.
Q4 C/C++ : Find if the given number is a power of 2.
Q5 C/C++ : Multiply x by 7 without using multiplication (*) operator.
Q6 C/C++ : Write a function in different ways that will return f(7) =
4 and f(4) = 7
Q7 Remove duplicates in array
Q8 Finding if there is any loop inside linked list.
Q9 Remove duplicates in an no key access database without using an
array
Q10 Write a program whose printed output is an exact copy of the
source. Needless to say, merely echoing the actual source file is not
allowed.
Q11 From a 'pool' of numbers (four '1's, four '2's .... four '6's),
each player selects a number and adds it to the total. Once a number
is used, it must be removed from the pool. The winner is the person
whose number makes the total equal 31 exactly.
Q12 Swap two numbers without using a third variable.
Given an array (group) of numbers write all the possible sub groups of
this group.
Q14 Convert (integer) number in binary without loops.

Al

http://www.praveen.ws/journal/2006/09/04/c-and-c-puzzles/
http://coding.derkeiler.com/Archive/C_CPP/comp.lang.c/2004-06/2652.html
http://www.velocityreviews.com/forums/t284024-programming-puzzle.html

without semicolon how to write c program

How to print something - say to write a code "hello world" without any semicolon.
Well the solution is very simple...






#include < stdio.h >
main() { if (printf("Hello, world!")) {} }

Al