code interview yingcai xiao hari krishna bodicharla
TRANSCRIPT
![Page 1: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/1.jpg)
Code Interview
Yingcai XiaoHari Krishna Bodicharla
![Page 2: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/2.jpg)
Code Interview
• What is it?• Books• The process• The questions• How to prepare?
![Page 3: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/3.jpg)
What is it?
• Code Interview: job interview involves designing and writing programs. (the contents relate to coding.)
![Page 4: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/4.jpg)
Digital Interview
• Digital Interview: online interview, video interview. The format relates to digital media. Can be real-time or pre-recorded.
![Page 5: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/5.jpg)
Digital Interview
"The Essential Digital Interview Handbook" by Paul J. Bailo
online interview,
good reference even for face-to-face interview.
![Page 6: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/6.jpg)
Books on Code Interview (in Safari)
•"Ace the Programming Interview: 160 Questions and Answers for Success“by Edward Guiness
•"Programming Interviews Exposed: Secrets to Landing Your Next Job" by John Mongan; Eric Giguere; Noah Kindler
•"Coding Interviews: Questions, Analysis & Solutions" by Harry He
![Page 7: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/7.jpg)
Books on Code Interview (not in Safari)
•"Cracking the Coding Interview: 150 Programming Interview Questions and Answers" by Gayle Laakmann McDowell
•"Cracking the C, C++, and Java Interview" by S G Ganesh
![Page 8: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/8.jpg)
The Process
• Usually after HR screening interview• Or after a phone interview• Can be online (digital)• Or face-to-face• Usually one-on-one with your interviewer. • You may have something to write on.
![Page 9: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/9.jpg)
The Process
• You will be asked to write some code. • May need to talk through the question first• May be in an actual programming language • May be as pseudo-code.
![Page 10: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/10.jpg)
The Questions
Compare two integers without using any comparison
operators?
![Page 11: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/11.jpg)
The Questions
Swap two integers without using a temp?
![Page 12: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/12.jpg)
The Questions
Which one is faster?
int I, J = 8;I = 0.5 * J;I = J / 2;I = J >> 1;
![Page 13: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/13.jpg)
• Array• Linked List• Array List• Hash Table• Queue• Stack• Tree• Graph
Data Structures
![Page 14: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/14.jpg)
Why different data structures?• Use minimum space (Array).• Fast to retrieve (Array).• Easy to search (Array, Indexing / Hashing, Tree).• Easy to modify (Linked List).• Persistent. (IDs not Pointers/References)• Sharable over the Internet. (XML)• Reduce coding errors. (Padded Array)
Data Structures
![Page 15: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/15.jpg)
Persistent. (IDs not Pointers/References)• There is no use to save pointers/references or transmit them over the Internet. • Serialization (memory automatically allocated during loading)• Use indexes to link data instead of pointers/references (indexed faceset)
Data Structures
![Page 16: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/16.jpg)
INDEX LINKED DATA STRUCTURE
![Page 17: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/17.jpg)
Data Structure for Graphics
and Visualization
![Page 18: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/18.jpg)
SERIALIZATION OF OBJECTS
![Page 19: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/19.jpg)
Serialization
• Converting an object into a form that can be persisted or transported.
• Save objects to permanent storages.• Sent over the network. • Pass on to another object.
![Page 20: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/20.jpg)
Deserialization
• Converts a stream into an object.
Together, these processes allow data to be easily stored and transferred.
![Page 21: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/21.jpg)
Requirements for Serialization To allow an object to be serializable:• In a serializable class, you must ensure that
every instance variable of the class is also serializable.
• The class must be visible at the point of serialization.
• All primitive types are serializable.
![Page 22: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/22.jpg)
Sample Code for Serialization// serializable class
class SerializeEmployee
{
public:
char character;
unsigned int id;
// serializing method
void Serialize(::std::ostream &os);
//static deserializing method
static SerializeEmployee Deserialize(::std::istream &is);
};
void SerializeEmployee::Serialize(std::ostream &os)
{
if (os.good())
{
os.write((char*)&character, sizeof(character));
os.write((char*)&id, sizeof(id));
}
}
![Page 23: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/23.jpg)
Sample Code for DeserializationSerializeEmployee SerializeEmployee::Deserialize(std::istream &is)
{
SerializeEmployee retval;
if (is.good())
{
is.read((char*)&retval.character, sizeof(retval.character));
is.read((char*)&retval.id, sizeof(retval.id));
}
if (is.fail()) {
throw ::std::runtime_error("failed to read full struct");
}
return retval;
}
![Page 24: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/24.jpg)
Serialization References
1. http://en.wikipedia.org/wiki/Serialization
2. http://www.slideshare.net/imypraz/java-serialization-8916554?v=qf1&b=&from_search=8
3. http://www.stackoverflow.com/questions/5707835/having-trouble-serializing-binary-data-using-ifstream-and-ofstream
![Page 25: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/25.jpg)
Sharable over the Internet. (XML)• Text based• User defined tags• No header• Inefficient
Data Structures
![Page 26: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/26.jpg)
Reduce coding errors. (Padded Array)• Bounds checker• Use padding cells at the beginning or end of an array.• Error if the padding cells were written to.
Data Structures
![Page 27: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/27.jpg)
Space Partitioning• Quad Tree (for rectangular shapes)• Triangulation (for irregular shapes)
Data Structures
![Page 28: Code Interview Yingcai Xiao Hari Krishna Bodicharla](https://reader031.vdocuments.net/reader031/viewer/2022032006/56649e1a5503460f94b0875b/html5/thumbnails/28.jpg)
• Bubble• Merge• Quick • Heap• Insertion
Sorting