Fortinet Interview Question for Software Engineer / Developers


Country: Canada
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
3
of 3 vote

int bin(int *arr,int l,int h,int k)
{
        int mid;
        if(l>h)
                return -1;
        if(l==h)
        {
                return arr[l]==k?l:-1;
        }
        else
        {
                mid=(l+h)>>1;
                if(arr[mid]==k)
                        return mid;
                else if(k>arr[mid])
                        return bin(arr,mid+1,h,k);
                else
                        return bin(arr,l,mid-1,k);
        }
}

- Aashish June 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

void CreateBSTAsennd(int s, int e)
{
	if(e-s==0)
	{
	 AddNode(n[e]);
	 
	}
	else if(e-s==1)
	{
     AddNode(n[s]);
	 AddNode(n[e]);
	}
	else
	{
	 AddNode(n[(s+e)/2]);
     CreateBSTAsennd(s,s+(e-s)/2-1);
     CreateBSTAsennd(s+(e-s)/2+1,e);
	}

}

- Anonymous December 26, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

also create a bstree with it , it is balanced

typedef struct bst {
int data;
struct bst * lc;
struct bst * rc;
} *bstree,*bstnode;

void AddNode(int e)
{
	static bstree root=NULL;
	bstnode q,f;
	bstnode p =(bstnode)malloc(sizeof(struct bst));
	if(p==NULL) return;
	memset(p,0,sizeof(struct bst));
	if(root==NULL) {root=p; return;}
	q=root;
	while(q)
	{
	  f=q;
      if(q->data>p->data)q=q->lc;
      else               q=q->rc;
	}
	if(f->data>p->data)
	{
		f->lc=p;
	}
	else
	{
        f->rc=p;
	}

}

- Anonymous December 26, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String arg[]){
		int arr[]={1,3,5,9,10};
		
		int size = arr.length-1;
		int index = size /2;
		int startIndex = 0;
		int endIndex = arr.length;
		int givenNumber = 1;
		while( true ){

			index = (startIndex+endIndex)/2;
			
			if( givenNumber == arr[index] ){
				System.out.println( "found here: "+ index);
				break;
			}
			else if( givenNumber<arr[index] ){
				if( endIndex == index )
					break;
				endIndex = index;
			}
			else{
				if( startIndex == index)
					break;
				startIndex = index;
			}
		}
	}

- apr June 24, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what will be the complexity of this solution ? O(Log n)??

- softy June 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think it will be log n base 2

- VM September 25, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int a[5]={1,3,5,7,9};
int h=0, t=4, k=5;
while(h<=t)
{
if(h==t)
{
if(k==h)
{
printf("find.....%d", h);

}
break;
}
if(k>a[(h+k)/2])
{
h=(h+k)/2+1;
t=t;
}else if(k<a[(h+k)/2])
{
h=h;
t=(h+k)/2-1;
}else
{
printf("find.....%d", (h+k)/2);
break;
}
}

- Bin December 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More