Skip to main content

Interview Questions

Problems on search/ sort
---------------------------

Q. Design an algorithm to find the duplicates in an array.

Given an array of random integers, write an algorithm in C that removes duplicated numbers and return the unique numbers in the original array.

E.g Input: {4, 8, 4, 1, 1, 2, 9} Output: {4, 8, 1, 2, 9, ?, ?}

void rmdup(int *array, int length){
int *current , *end = array + length - 1;

for ( current = array + 1; array < end; array++, current = array + 1 ){
  while ( current < end ){
    if ( *current == *array ){
        *current = *end--;
    }
    else{
        current++;
    }
 }// while ends ... } // for ends ... } // func ends
=====================
Q. Given an array of length N containing integers between 1 to Nm determine if it contains any duplicates.

How can we efficiently find out if any of those numbers are duplicates ? To know only

The easiest approach is to make a hash table to keep track of the numbers we've seen so far.
Something like this:

Given an array A of length n,

let h ← (new hash table)
for 1 <= i <= n:
if A[i] is present in h: return A[i]
set h[A[i]] ← True
return

OR ALTERNATIVELY

let s ← array [1..n]
initialize s to all zeroes
for 1 <= i <= n:
if s[A[i]] > 0: return A[i]
set s[A[i] ← 1

IF we have constant space; no more creating hash tables and arrays on the fly

Since there are n values from 1 to n-1 with one duplicate, we can use the fact that the sum of the integers from 1 to m is (m*(m+1))/2, take the sum from 1 to n-1, subtract that from the actual sum of numbers in the array, and the result will be the duplicated number:

let s ← 0
for 1 <= i <= n:
s ← s + A[i]
return s - n*(n-1)/2

==============
Suppose you have an array of 1001 integers. The integers are in random order, but you know each of the integers is between 1 and 1000 (inclusive). In addition, each number appears only once in the array, except for one number, which occurs twice. Assume that you can access each element of the array only once. Describe an algorithm to find the repeated number. If you used auxiliary storage in your algorithm, can you find an algorithm that does not require it?

int findDup (int *a, int len) { // len is 1001 here
int found, i, t;

for (i = 0; i < len; i++) {
t = a[i] > 0 ? a[i] : -a[i];

if (a[t] > 0)
a[t] = -a[t]; // use negative as a mark
else { // if it is already marked, it must be a dup!
found = t;
break;
}
}

for (i = 0; i < len; i++)
a[i] = (a[i] > 0) ? a[i] : -a[i]; // restore the array

return found;
}
===================
Q. Program to remove duplicates from a sorted array.

Q. There is a fixed size list of no, given that how to find out if an element in 2nd list (fixed size)
is present in the first list.
===================
Q. Find contiguous subarray within an given array of integers.
void maxSumSubArray( int *array, int len, int *start, int *end, int *maxSum )
{
int maxSumSoFar = -2147483648;
int curSum = 0;
int a = b = s = i = 0;
for( i = 0; i < len; i++ ) {
curSum += array[i];
if ( curSum > maxSumSoFar ) {
maxSumSoFar = curSum;
a = s;
b = i;
}
if( curSum < 0 ) {
curSum = 0;
s = i + 1;
}
}
*start = a;
*end = b;
*maxSum = maxSumSoFar;
}
===================
Q. Find the 2 numbers where the difference is minimum among the set of numbers.




3. Data Structures 

 3.a Link list problems +
    http://cslibrary.stanford.edu/105/LinkedListProblems.pdf
 3.b - Hash

 3.c - Binary Trees
 3.d -
Miscellaneous Links
Reb-Black Tree +
http://www.cs.princeton.edu/~rs/talks/LLRB/RedBlack.pdf
http://www.cs.princeton.edu/courses/archive/fall08/cos226/lectures/10BalancedTrees-2x2.pdf
Trie Implementation Example +
http://www.cs.bu.edu/teaching/c/tree/trie/

4. Linux System

5. Ip table and NAT related info +
https://www6.software.ibm.com/developerworks/education/l-packet/l-packet-a4.pdf
http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch14_:_Linux_Firewalls_Using_iptables
http://books.google.com.sg/books?id=T8V02u2jDP0C&pg=PT152&lpg=PT152&dq=ip+packet+processing+linux&source=bl&ots=6GXbsRfLJ_&sig=q781FGrsp0twWNcB_K-ol_spFCo&hl=en&ei=QdImTs-TK8yHrAez3vSsCQ&sa=X&oi=book_result&ct=result&resnum=10&ved=0CFoQ6AEwCTgU#v=onepage&q=ip%20packet%20processing%20linux&f=false
http://www.wisdomjobs.com/e-university/linux/chapter-180-277/the-linux-tcp-ip-stack.html
http://www.ecsl.cs.sunysb.edu/elibrary/linux/network/recvpath.pdf
http://www.google.com.sg/#q=ip+packet+processing+linux&hl=en&prmd=ivnsb&ei=BtImTozqLcjVrQeflO2vCQ&start=20&sa=N&fp=97340d1897d20133&biw=1280&bih=892
http://www.cookinglinux.org/pub/netdev_docs/iprecv2.pdf

Interview questions +
http://www.mytechinterviews.com/reverse-the-order-of-words-in-a-string

http://rapidtrend.com/f/1917556/the_art_of_computer_programming_2nd_ed_vol3_donald_knuth.html

Linux +
Intruppt Handler ++
IP Packet Processing ++

Comments

Popular posts from this blog

NSSF - an 5G network function to support the network slicing

NSSF - Network Slice Selector Function The 5G System architecture (3GPP TS 23.501: 5G SA; Stage 2) consists of the following network functions (NF). - Authentication Server Function (AUSF) - Core Access and Mobility Management Function (AMF) - Data network (DN), e.g. operator services, Internet access or 3rd party services - Structured Data Storage network function (SDSF) - Unstructured Data Storage network function (UDSF) - Network Exposure Function (NEF) - NF Repository Function (NRF) - Network Slice Selection Function (NSSF) ======>>> our focus - Policy Control function (PCF) - Session Management Function (SMF) - Unified Data Management (UDM) - Unified Data Repository (UDR) - User plane Function (UPF) - Application Function (AF) - User Equipment (UE) - (Radio) Access Network ((R)AN)

SMS-SG on LTE/ MTC networks

SMS with LTE  (SG-SMS) SMS (Short Messaging Service) was quite popular among people during 2G/3G, but now with the advent of 4G losing the shine/ attraction. With 4G people are moving to always-on kind of data connectivity and thus market rising with many application options to provide the messaging capabilities. The examples are such as whatsapp, snapchat etc Now here we are going to discuss, “can an SMS possible in LTE technology ?” and if so “how?” One possibility of using IMS framework and delivering SMS to/from UE. IMS provides the data (e.g. data, media-voice/video) usage overlaid on LTE technology. The bigger question and climax is on market pace in adapting and deployment of the IMS. To address the feature availability, an interim solution (SG interfaces) are suggested in specs. (its similar on the lines on how CS fallback option before LTE supporting Voice calls) Lets revisit the past (2G) on how SMS are delivered. SMS is delivered over signaling channel. This me

Cloud based Frameworks/ Kubernetes environment

Cloud based microservice frameworks Some of open source platforms available are Swarm (Docker), Kubernetes (google), mesos, The most popular in communities and internet industry seems to be kubernetes and picking steam in telecom front as well for upcoming 5G Service based architecture. The kubernetes has the default container solution based on Rket ? but the most popular combinations are using Docker as container. Kubernetes/ an Cloud orachastrator !! Deployment automation of scaling in (zooming in/ increasing) and out (zooming out, decreasing) Network plugin available such as flannel (popular, support only IPv4), calico (support IPv4, IPv6), weavenet Kubernetes currently does not support dual stack IPv4, IPv6 inter-working etc capabilities till version 1.13 (dec 2018). Another limitation, it does not recognize the multiple interfaces in case enable to POD's for configuring services exposure and external communication till version 1.13 (dec 2018) Will be adding more