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


Monday, September 3, 2007

.getClass() vs instanceof

class Parent {}
class Child extends Parent {}

Child c = new Child();

c instanceof Parent is true
c.getClass().equals(Parent.class) is false


bye
Al (alokadvin)

mypictr - we make your profile picture

Hey ,
find a cool way to edit your pictures on-line

mypictr - we make your profile picture

Al

Sunday, September 2, 2007

Affine Cipher Deciphered

Hi

Affine Ciphers -
An encipherment scheme (or algorithm) of the form
E (x) = (ax + b) MOD 26
is called an affine cipher. Here x is the numerical equivalent of the given plaintext letter, and a and
b are (appropriately chosen) integers.

What are the possible values for which one to one ciphers are possible...
i.e if p and q are two plaintext such that p ne q then E(k,p) ne E(k,q).

The function E (x) = (ax + b) MOD 26 defines a valid affine cipher if a is relatively prime to 26, and b
is an integer between 0 and 25, inclusive. If b = 0, then we refer to this cipher as a decimation cipher.
(Note that since there are 12 valid choices of a and 26 valid choices of b, there are 12 × 26 = 312 possible
valid affine ciphers.)
Also note that if a = 1, then E (x) = (x + b) MOD 26 is simply a Caesar (+b) shift cipher.

Do more with affine cipher @ http://home.clara.net/paulwlocke/portfolio/affine.html

bye

Sunday, August 26, 2007

polymorphism in C

Even polymorphism can by implemented in C. Polymorphism in Java and C++ is implemented by associating with each instance a table of functions. Polymorphic method names are converted to indexes into this function table. When a method call on a particular instance is executed, the function table for that instance (actually these tables are shared among the instances of a class), used to find the proper function to execute.

Since C has the ability to store pointers for functions as a basic data type, and the ability to calla function from such a function pointer. It is straightforward (though not always fun) to explicitly duplicate the function table mechanism and implement polymorphisms by hand.

Al

How to read C declarators PART 2

Function pointers and combinations

The C "forward" declaration:

 1.) extern int foo();

just says that foo is a function returning int. This follows the same pattern for reading declarators as you saw in previous post. Start at foo and look right. You see () so say function. You look left and see int. Say int.

        2.) extern int *foo();

Yep, you say foo is a function returning a pointer to int.

Now for the big leap. Just like we can make a pointer to an int or whatever, let's make a pointer to a function. In this case, we can drop the extern as it's no longer a function forward reference, but a data variable declaration. Here is the basic pattern for function pointer:

 3.) int (*foo)();

You start at foo and see nothing to the right. So, to the left, you say pointer. Then to the right outside you see function. Then left you see int. So you say foo is a pointer to a function returning int.

Here is an array of pointers to functions returning int:

 4.) int (*Object_vtable[])();

One last, incredibly bizarre declaration, for fun:

 5.) int (*(*vtable)[])();

This pointer to a vtable is set to the address of a vtable.

In summary:

 int *ptr_to_int;
int *func_returning_ptr_to_int();
int (*ptr_to_func_returning_int)();
int (*array_of_ptr_to_func_returning_int[])();
int (*(*ptr_to_an_array_of_ptr_to_func_returning_int)[])();

regards
Al

How to read C declarators PART 1

Reading C declarators in a precise manner.

The rule goes like this:

"Start at the variable name (or innermost construct if no identifier is present. Look right without jumping over a right parenthesis; say what you see. Look left again without jumping over a parenthesis; say what you see. Jump out a level of parentheses if any. Look right; say what you see. Look left; say what you see. Continue in this manner until you say the variable type or return type."


The degenerate case is:

int i;

Starting at i, you look right and find nothing. You look left and find the type int, which you say. Done.

Ok, now a more complicated one:

int *a[3];

Start at a. Look right, say array of size 3. Look left and say pointer. Look right and see nothing. Look left and say int. All together you say a is an array of size 3 pointers to int.

Adding parentheses is when it gets weird:

int (*a)[3];

The parentheses change the order just like in an expression. When you look right after a, you see the right parenthesis, which you cannot jump over until you look left. Hence, you would say a is a pointer to an array of 3 ints.


bye for now
Al

Friday, August 24, 2007

Object oriented modelling in C - PART 3 - Inheritance

Inheritance is a mechanism by which new and more specialized classes can be defined in terms of existing classes. When a child class (subclass) inherits from a parent class (superclass), the subclass then includes the definitions of all the attributes and methods that the superclass defines. Usually, the subclass extends the superclass by adding its own attributes and methods. Objects that are instances of the subclass contain all data defined by the subclass and its parent classes, and they are able to perform all operations defined by this subclass and its parents.

This kind of class relationship can be implemented in C by embedding the parent class attribute structure as the first member of the child class structure. This structuring results in such an attribute alignment that a pointer to the Child class can always be safely cast (upcast) on the pointer to the Parent class. In particular, this pointer can always be passed to any C function expecting a pointer to the Parent class. (To be strictly correct in C, you should explicitly upcast this pointer.) This means that all methods of parent classes are automatically available to child classes-in other words, they are inherited.

Object oriented modelling in C - PART 2 - Encapsulation

You can achieve packaging of data with functions in C by making each class attribute (instance variable) a field in the C struct. You implement class methods as C functions that take as their first argument the pointer to the structure of attributes (the this pointer). You can further strengthen the association between the attributes and methods by a consistent naming convention for method names. The most popular convention that I adopt is to concatenate the structure name (class name) with the operation name. This altering of function names is part of name decorating (also known as name mangling) and is performed implicitly by most C++ compilers. Because name decorating eliminates method name clashes between different classes, it effectively partitions the flat C function namespace into separate namespaces nested within classes.

The next aspect I address by a coding convention is access control. In C, you can only indicate your intention for the level of access permitted to a particular attribute or a method. Conveying this intention through the name of an attribute or a method is better than just expressing it in the form of a comment at the declaration point. In this way, unintentional access to class members in any portion of the code will be easier to detect. Most OO designs distinguish the following three levels of protection:

  • private-accessible only from within the class
  • protected-accessible only by the class and its subclasses
  • public-available anywhere (de-fault in C)
Optionally, a class may provide a destructor, which is a method responsible for releasing the resources allocated during the lifetime of an object. Whereas there may be many ways of instantating a class (different constructors taking different arguments), there should be only one way of destroying an object.


Object oriented modelling in C - PART 1

In spite of unquestioned advantages of OO languages, C still remains the best known and widespread implementation language. Most developers still exclusively use procedural programming techniques, and many are unaware that it's quite easy to implement key OO concepts directly in C. Promoting this awareness may be important for at least two reasons.

The first is leveraging OO technology. Most OO designs can be implemented in C, but many developers wouldn't consider them without the availability of an OO language. This unnecessarily limits application of the technology.

The second is smoothing transition from procedural to OO thinking. Migrating to OO technology can require quite a leap in your way of thinking. Implementing OO concepts in currently used and familiar languages gives you an opportunity to get exposed to the new programming paradigm right away and without major investment.


Al

Friday, August 17, 2007

Download video from youtube

It's strange that none of the video sharing sites provide a simple one-click button to download videos. So we will have to take the help of easy workarounds to download the videos. Here are three different ways to download any video from the internet though internally, they employ the same hack (Right-click -> "Save Target As" OR copy the link into your download manager. but change the file extension to .flv)

Approach 1: The easiest way is to copy your video URL and paste it on KeepVid Lite. When you click submit, you will be provided with a link to save the video as an FLV file.

Approach 2: Bookmark this Link or drag it your browser links toolbar. When you want to download a certain video, open the link in your browser and click the KeepVid button.

Approach 3: For Firefox Users - Install the VideoDownloader Extension from Mozilla Addons website - It downloads all embedded objects on a webpage including the video clips.

read more on
http://labnol.blogspot.com/2006/07/10-interesting-things-you-can-do-with.html

bye

Thursday, August 16, 2007

Embed Audio Files in HTML pages

To add the wav file to your html page use the following:

#EMBED src="file.wav" autostart=true loop=false volume=100
hidden=true@#NOEMBED@#BGSOUND src="file.wav"#/NOEMBED@


replace - @ with >
replace - # with <
Where the a file named file .wav has been uploaded to your site in the same directory as the page which contains the EMBED tags.

In the above example where autostart=true, the file will automatically start playing. Use this tag for background sound which should start immediately once it is downloaded.

You can also use loop=true where you want the sound to repeat over and over. By editing a short sound and using the loop=true option you can create continuous audio from a very short audio cut. For example: waves, applause, engine sounds and so on.

get more on
http://www.tips-tricks.com/sound.asp

bye
AL

Basic Information About Sound Files

So start with some audio formats, which might be helpful in adding audio features in my web pages.

The two most widely supported file formats for sound files are MIDI and WAV. As with graphic files, you'll want to keep the size of the file as small as possible while maintaining quality.

The differences between WAV and MIDI are that MIDI files are generally a great deal smaller, however, many types of audio, such as speech, don't work well as MIDI files. MIDI is a good file format for music. A one minute WAV file can be as large as 1MB in size, while a 1 minute MIDI file can be less than 25K. Using software convertors, it may be possible to resample WAV files to reduce their file size.

Some helpful and interesting links are -


  1. The Wav Place - offers movie audio clips, cartoon sounds, and music files
  2. MidiWeb - offers technical information about MIDI files and MIDI interfaces, a library of download able MIDI files.
  3. FileCity offers a huge archive of MIDI files, including movie theme songs, rock music, holiday songs, and more.
  4. MidiFarmalso offers a library of downloadable MIDI files.
  5. WavCentral offers a huge archive of audio files that you can download.
  6. MovieWavs offers...you guessed it! Wav files from popular films.
bye for now
AL