Akamai Interview Question for SDE-2s


Country: India
Interview Type: Phone Interview




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

My order of preference

Performance
* Reference
* Pointer
* Object

Maintability/Debug
* Reference
* Object
* Pointer

Reason:
- Performance: Reference and Pointer are equaly well since it introduce no overhead, object might require copy which is very expensive if the size of the object is large. Reference is better then pointer since it require no extra test to see the refered object exist.

- Maintainability: it is generally well-know that raw pointer cause more trouble so people prefer to use smart pointer, you have to be very careful to use the raw pointer to make sure the refered object is valid and clean up the memory after all. Reference can be used anywhere object can be used.

@As mentioned in the below comment. It would be better to use const reference (const object and pointer) if you don't want to change the value of refered objects, it also help compiler to produce more optimized code

- LinhHA05 July 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

std::vector of a reference type would cause undefined behavior, because vector element must be assignable and copy-constructible (in c++03).

- boost.lists November 09, 2013 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 vote

your answer seems good only thing is if you are taking reference or pointers then any change made might impact the original so a const reference or a const pointer would be better and the usage of these three, i.e., reference, pointer, and object (pass by value) depends on the context of what is required.

- S@iR@m July 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

jk

- Anonymous August 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. by value container written for supporting by value
2. by pointer If you want to use pointer you will responsible for delete the pointer in vector better you will use shr_ptr
3. by reference difficult to maintain in case of assignment or copy con

- Anonymous August 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If vector is needed to share among other class objects or outside your code block, reference option is gone.

use of objects in vector require copies created. This is more portable and simple but if objects are heavy in size or resouces, this option is gone too.

Pointers require dynamic allocation of your objects and deletion of them at some point where the usage is completed. This requires some programming discipline which is difficult to ask for. Smart pointers in the vector may give a solution to your need if usage of new is not threatening to your principles/standards.

- MadhaviA September 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think we can't create vector of references.

- prshu September 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yep, you can not create a container of references. Also, vectors have the resize problem, so if the vector runs out of its initial memory, a new vector is made in the memory elsewhere which 'copies' the objects in a vector. This might cause problems with a vector of pointers. The answer depends on the context but these are few pointers to remember.

- Random February 15, 2014 | Flag


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