Arista Networks Interview Question for Software Developers
- 0of 2 votes
Answers#include <stdio.h>
- aristainterview October 19, 2016 in United States
int main( int argc, char* argv[] ){
char* string1 = "string";
char string2[] = "string";
}
#include <stdio.h>
/* Describe the code below */
struct s {
double f;
int i;
char c[3];
void *p;
int x[0];
};
int main( int argc, char ** argv ) {
struct s temp;
printf("The size of the struct is %d \n", sizeof(temp));
printf("The size of the double is %d \n", sizeof(temp.f));
printf("The size of a character array is %d \n", sizeof(temp.c));
printf("The size of a void pointer is %d \n", sizeof(temp.p));
printf("The size of a integer array is %d \n", sizeof(temp.x));
printf("The size of a integer is %d \n", sizeof(temp.i));
return 0;
}
/* What's wrong with this program? */
#include <stdio.h>
int
main( int argc, char const * argv ) {
for( int i = 0; i < argc; ++i ) {
printf("%s\n", argv[i] );
}
}
/* Can you tell me what the program will do when I run it like this:
* <prog> 1 2 3 4
*/
/*
Describe what two of these do, and how they're useful for debugging:
perf
oprofile
gprof
strace
gcov
printf
syslog
*/
#include <stdlib.h>
#include <stdio.h>
class C {
public:
void func() {
printf("func called\n");
}
virtual void virtualFunc() {
printf("virtual func called\n");
}
};
int main (int argc, char ** argv) {
C * obj = NULL;
/* What does the following print? */
obj->func();
/* What does the following print? */
obj->virtualFunc();
/* What's the difference? */
}
/* What's polymorphism? */
/* What's abstraction? */
#include <cstdlib>
#include <ctime>
#include <sys/time.h>
#include <iostream>
#include <cstdio>
using namespace std;
/* What do this do? */
int a( unsigned int i ) {
int c = 0;
while( i ) {
if( i & 1 ) { c++; }
i >>= 1;
}
return c;
}
/* What does this one do? */
int b( unsigned int i ) {
static unsigned char n[] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
int c = 0;
while( i ) {
c+=n[i&15];
i >>= 4;
}
return c;
}
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;
std::string::iterator contains(char c, string s1) {
std::string::iterator i = std::find(s1.begin(), s1.end(), c);
if (i != s1.end())
return i;
else
return null;
}
int anagram ( const string s1, const string s2) {
for( int i = 0; i < s1.size(); i++) {
std::string::iterator i = ,s2.find(s1[i]);
if (i != s2.end())
s2.erase(i);
else
return false;
}
return s2.size()==0;
}
int main (int argc, char *argv[] ){
printf("%d",anagram(argv[1],argv[2]));
}
F
/ \
/ \
D M
/ \ / \
B E L P
/ \ / \
A C H S
/ \
R T
In-order traversal:
A->B->C->D->E->F->H->L->M-P->R->S->T
Requirement:
Write a function (pseudo-code is fine) that given a starting node, advances to the next in-order node in a binary tree.
Please also provide a data-structure definition of a node.
struct node
{
};
node *next_node(node *current)
{
node *next;
/* current - any node in the tree, advance to next node */
return next;
}
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
/*
vercmp compares two software version strings and returns the following:
if v1 > v2 : return 1
if v1 == v2 : return 0
if v1 < v2 : return -1
input strings are in the form "1.0.3", "2.10", "6.0.0.3", etc...
"1.0" is considered bigger than "1" and "1.10" is greater than "1.2"
*/
int vercmp( char * v1, char * v2 ) {
}
int main() {
assert( vercmp( "1.1", "1.0" ) == 1 );
assert( vercmp( "1.0", "1.1" ) == -1 );
assert( vercmp( "1.0", "1.0" ) == 0 );
assert( vercmp( "1", "1.0" ) == -1 );
assert( vercmp( "1.0", "1" ) == 1 );
return 0;
}
Describe in 5 minutes or less what one of these protocols is:
BGP
OSPF
ISIS
PIM-SM
IGMP
STP
DHCP
Could you configure a network device (EOS, Cisco, Linux, JunOS, Quagga, etc.) to
enable any of these?
Pick one of these data structures and tell me everything you know about it:
Red-black tree
B-tree
Patricia
Avl Tree
Trie
Or describe a data structure that can store a set of integers.
If you're not familiar with any of the above, tell me what you know about
one of these:
Bit vector
Binary tree
std::vector
Doubly Linked List
#!/usr/bin/python
# Write a program to num up the Nth column of integers in a file that has
# M columns in it.
What do these tools do?
tcpdump
ping
wireshark
traceroute
ifconfig
ip
netstat
What seven system calls do you use to implement a TCP server?
#include <stdio.h>
#include <stdlib.h>
#include "list.h"
/**
* Given a linked list of the structure:
struct node {
int val;
struct node* next;
};
print out the fibonacci nodes e.g. the 1st, 2nd, 3rd, 5th, 8th... nodes
up until the list ends.
*/
int main( int argc, char** argv ) {
if( argc != 2 ) {
printf( "usage fib num --you gave %d args\n", argc - 1 );
exit( 0 );
}
int nodes = atoi( argv[ 1 ] );
if( nodes < 1 ) {
printf( "num must be a positive number --you gave %d\n", nodes );
}
struct node* list = createList( nodes );
// ...
freeList( list, nodes );
}
include <stdlib.h>
#include <assert.h>
struct node {
int val;
struct node* next;
};
struct node* createList( int nodes );
struct node* freeList( struct node* list, int nodes );
struct node* createList( int nodes ) {
int i = 0;
struct node* list =
( struct node* ) malloc( sizeof( struct node ) * nodes );
assert( list );
for( i = nodes - 1; i >= 0; --i ) {
list[ i ].val = ( nodes - i ) - 1;
list[ i ].next = list + ( i - 1 );
}
list[ 0 ].next = NULL;
return &list[ nodes - 1 ];
}
struct node* freeList( struct node* list, int nodes ) {
free( &list[ 1 - nodes ] );
}
#include <stdio.h>
#include <assert.h>
#include <stdbool.h>
extern bool isPalindrome( const char * );
int main() {
assert( isPalindrome( "civic" ) == true );
assert( isPalindrome( "evitative" ) == true );
assert( isPalindrome( "radar" ) == true );
assert( isPalindrome( "stats" ) == true );
assert( isPalindrome( "abba" ) == true );
assert( isPalindrome( "aba" ) == true );
assert( isPalindrome( "aBa" ) == true );
assert( isPalindrome( "statss" ) == false );
assert( isPalindrome( "abracadabra" ) == false );
printf( "Lower case palindromes passed!\n" );
assert( isPalindrome( "ABa" ) == true );
assert( isPalindrome( "cIviC" ) == true );
printf( "Upper/lower cases examples passed!\n" );
assert( isPalindrome( "" ) == false );
assert( isPalindrome( NULL ) == false );
printf( "No string/empty string corner cases passed!\n" );
printf( "Nailed it!! Congratulations!\n" );
return ( 0 );
}
#include "caesar.h"
#include <stdlib.h>
char rotate(const char in, char pivot, int offset)
{
return pivot + (in - pivot + offset) % 26;
}
void caesar(const char *in, char *outbuf, int offset)
{
int i;
char *out = outbuf;
for (; *in; ++in, ++out) {
if (*in >= 'A' && *in <= 'Z')
*out = rotate(*in, 'A', offset);
else if (*in >= 'a' && *in <= 'z')
*out = rotate(*in, 'a', offset);
else
*out = *in;
}
*out = 0;
}
#include "caesar.h"
#include <stdlib.h>
#include <stdio.h>
int
main(int argc, char *argv[])
{
char *buf = strdup(argv[1]);
caesar(buf, buf, 13);
printf("%s\n", buf);
free(buf);
return 0;
}
struct Tree {
struct Tree * left; // for bst, check all nodes are less than parent
struct Tree * right; // for bst, check all nodes are greater than parent
int value;
}
bool isBst( Tree * tr ) {
return (tr, INT_MIN, INT_MAX);
}
bool helpIsBst(Tree * root, int min, int max) {
if (root == NULL) return 1;
return ( root->value < max && root->value > min
&& helpIsBst(root->left, min, root->value)
&& helpIsBst(root->right, root->value, max));
}
Example BST:
*
* 8
* / \
* 4 12
* / \ / \
* 1 7 11 20
*/
struct node {
int value;
struct node *left, *right, *parent;
}
/* print the bst in-order */
void printBst( struct node *n ) {
}
struct node * findMin( struct node *n ){
}
struct node * findNext( struct node *n ) {
}
void foo( struct node *root) {
for( struct node * n = findMin(root); n; n = findNext(n) ) {
printf( "%d ", n->value );
}
}
#include <cstdio>
// 10
// / \
// 5 16
// / \ / \
// 3 11 14 17
struct node {
int value;
node * left;
node * right;
node * parent;
node( int value, node * left, node * right, node * parent=NULL ) : value( value ), left( left ), right( right ), parent( parent ) {}
};
// Test functions
void connect_parents( node * n, node * parent ) {
if( n ) {
n->parent = parent;
connect_parents( n->left, n );
connect_parents( n->right, n );
}
}
node * construct_tree() {
node * root = new node(
10,
new node( 5,
new node( 3, NULL, NULL ),
new node( 9, NULL, NULL ) ),
new node( 16,
new node( 14, NULL, NULL ),
new node( 17, NULL, NULL ) ) );
connect_parents( root, NULL );
return root;
}
int main() {
node * root = construct_tree();
// for( node * n = find_min( root ); n; n = find_next( n ) ) {
// printf( "%d\n", n->value );
return 0;
}
1. Create account for interviewee
$ tempaccount <username>
2. Login to recruit.arista.com as interviewee
$ ssh username@recruit.arista.com # passwd=aristarecruit
3. Install interview questions into temp account
$ cp ~bterrell/screeningQuestions.gz .
$ tar xvfz screeningQuestions.gz
$ rm screeningQuestions.gz
4. Start tmux on my shell with two panes
$ cp ~bterrell/.tmux.conf ~/.
$ tmux new -s interview
- ctrl+\, "-" to split panes
5. Meet with interviewee (or telecon)
$ ssh username@recruit.arista.com # passwd=aristarecruit
$ tmux attach -t interview"
- switch panes with ctrl+\, <up-or-down arrow>
#include <stdio.h>
#include <stdlib.h>
/* Example BST:
*
* 8
* / \
* 4 12
* / \ / \
* 1 7 11 20
*/
typedef struct node {
int value;
struct node *left, *right, *parent;
} node_t;
struct node * findMin( struct node *n ) {
for(; n && n->left; n = n->left) ;
return n;
}
struct node * findNext( struct node *n ) {
if(n->right) {
return findMin(n->right);
}
else {
for(; n->parent; n=n->parent) {
if(n->parent->left == n) {
return n->parent;
}
}
return NULL;
}
}
/* print the bst in-order */
void printBst( struct node *n ) {
if(n->left) {
printBst(n->left);
}
printf("%d ", n->value);
if(n->right) {
printBst(n->right);
}
void printBstNR( struct node *root) {
node_t* n;
for( n = findMin(root); n; n = findNext(n) ) {
printf( "%d ", n->value );
}
}
node_t* insertNode(node_t** root, int newval)
{
node_t *n;
if(!(*root)) {
n = (node_t*)calloc(1, sizeof(node_t));
n->value = newval;
*root = n;
}
else if(newval < (*root)->value) {
n = insertNode(&((*root)->left), newval);
if((*root)->left == n) n->parent = *root;
}
else {
n = insertNode(&((*root)->right), newval);
if((*root)->right == n) n->parent = *root;
}
return n;
}
int main()
{
node_t* root = NULL;
int data[] = { 8, 4, 12, 1, 7, 11, 20 };
int i, len = sizeof(data) / sizeof(int);
for(i=0; i < len; i++) insertNode(&root, data[i]);
printf("\ntraversal w/o recursion: ");
printBstNR(root);
printf("\ntraversal w/o recursion: ");
printBstNR(root);
printf("\ntraversal w/ recursion: ");
printBst(root);
printf("\n");
return 0;
}
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;
int anagram ( const string s1, const string s2) {
for( int i = 0; i < s1.size(); i++) {
int x = s2.find(s1[i]);
if (x != string::npos)
s2.erase(x);
else
return false;
}
return s2.size()==0;
}
int main (int argc, char *argv[] ){
printf("%d",anagram(argv[1],argv[2]));
}| Report Duplicate | Flag | PURGE
Arista Networks Software Developer