Wednesday, December 30, 2009

for programming interviews part5

hi
today we shall discuss simple problems like


9.Write, efficient code for extracting unique elements from a sorted
list of array. e.g. (1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9) -> (1, 3, 5, 9 }


#include < iostream >
int main()
{
using namespace std;
int a[20]={1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9};
int i=0,k=0;
for(i=1;i < 20 ; ++i)
{
if(a[k]==a[i])
continue;
else
{
++k;
a[k]=a[i];
}
}
for(i=0;i < k ; ++i )
cout << a[i];
cin.sync();
cin.get();
return 0;
}


10
Give a fast way to multiply a number by 7

#include < iostream >
int main()
{
using namespace std;
long long int a=0;
cin>>a;
long long int k=a;
k=( a << 3 )-k;
cout << k;
cin.sync();
cin.get();
return 0;
}

11
how to remove characters of string2 from string1

#include < iostream >
#include < string >
#include < map >
int main()
{
using namespace std;
char s1[10],s2[10];
int i=0,j=0;
cout<< "nter string 1";
cin >> s1;
cout << "nter string 2";
cin >> s2;
map < char , int > mp;
i=0;
while(s2[i])
{
mp[s2[i]]=1;
++i;
}
int k=0;
while(s1[i])
{
if(!mp[s1[i]])
s1[k]=s1[i];
//cout << s1[k];
++k;
++i;
//cout << s1;
}

for(i=0; i < k; ++i)
cout << s1[i];

//cout << s1 << endl;
cin.sync();
cin.get();
return 0;
}

11.how does a bootstraploader work in a linux

whoa that was shocker.............!!!!!!!!!!.
dont worry
->the BIOS takes the H/W platform specific tasks
->Once the H/W is recognised and started correctly the BIOS loads and executes partition code
->the boot loader presents the user with the various boots options,it then loads the OS after decompressing it from memory and sets H/W and memory management before calling the start_kernel() method
->the start_kernel() performs major operations for initializations and spawing process like init(),schedulers.
->scheduler-it takes care of sys management when kernel goes dormant
->init-it takes care of displaying user scripts for non OS services that are available for user environment.
->the user gets login screen.


whats difference between segmentation and paging
segmentation->it basically has logical units of arbitrary size
it has user protection,its visible to user via programs
paging-its basically physical units of fixed size it remains hidden from user and not visible in his program.

No comments:

Post a Comment