Western Digital
10+ Interview Questions and Answers
Q1. In DSA part, 1. Code for merge sort 2. Check if two trees are mirror 3. Find element in rotated sorted array 4. Check if linked list is palindrome 5. Detect a loop in linked list 6. Remove loop in linked list
List of DSA questions including merge sort, tree mirror check, rotated sorted array search, linked list palindrome and loop detection and removal.
Merge sort is a divide and conquer algorithm that sorts an array in O(nlogn) time complexity.
To check if two trees are mirror, we need to compare their left and right subtrees recursively.
To find an element in a rotated sorted array, we can use binary search algorithm.
To check if a linked list is palindrome, we can use stack or recu...read more
Q2. What is structure padding and why it happens?
Structure padding is the insertion of unused bytes between members of a structure to align the data in memory.
Padding is added to ensure that each member of the structure is aligned to a memory address that is a multiple of its size.
Padding can be compiler-dependent and can vary based on the target architecture.
Padding can affect the size of the structure and the performance of the program.
Example: struct MyStruct { char a; int b; char c; }; - padding will be added between a ...read more
Q3. map vs unordered_map, vector vs list
map and unordered_map are associative containers while vector and list are sequence containers.
map and unordered_map are used to store key-value pairs while vector and list are used to store sequences of elements.
map and unordered_map provide faster search and insertion of elements while vector and list provide faster insertion and deletion of elements.
map and unordered_map use red-black trees and hash tables respectively while vector and list use arrays and linked lists resp...read more
Q4. Code for fibonacci series
Fibonacci series is a sequence of numbers where each number is the sum of the two preceding ones.
Declare variables for first, second and next numbers
Initialize first and second numbers as 0 and 1 respectively
Loop through the desired number of terms and calculate the next number as the sum of the previous two
Store the result in an array
Return the array
Q5. What do you know about HDD?
HDD stands for Hard Disk Drive, a data storage device used in computers to store and retrieve digital information.
HDDs use magnetic storage to store data on spinning disks called platters.
They have read/write heads that move across the platters to access and modify data.
HDDs are typically used for long-term storage of large amounts of data in desktops, laptops, servers, and other devices.
Examples of HDD manufacturers include Seagate, Western Digital, and Toshiba.
Q6. Synchronisation of given thread blocks
Synchronizing thread blocks is important for efficient and correct execution of parallel programs.
Thread blocks must be synchronized to avoid race conditions and ensure correct program output.
Synchronization can be achieved using locks, semaphores, or barriers.
Examples of synchronization include ensuring that shared resources are accessed by only one thread at a time, or that threads wait for each other before proceeding.
Synchronization can also be used to optimize program pe...read more
Q7. Explain dynamic polymorphism
Dynamic polymorphism is the ability of an object to take on multiple forms during runtime.
It allows objects of different classes to be treated as if they are of the same class.
It is achieved through virtual functions and inheritance.
Examples include function overriding and templates in C++.
Q8. Types of casts in C++
C++ has four types of casts: static_cast, dynamic_cast, const_cast, and reinterpret_cast.
static_cast is used for implicit conversions between related types
dynamic_cast is used for runtime type checking and casting of polymorphic types
const_cast is used to remove const or volatile qualifiers from a variable
reinterpret_cast is used for low-level casting between unrelated types
Examples: static_cast
(3.14), dynamic_cast (basePtr), const_cast (str), reinterpret_cast (&ptr)
Q9. Functors in C++, uses
Functors are objects that can be treated as functions in C++. They are used for generic programming and can be passed as arguments.
Functors are often used in algorithms that require a function object as a parameter.
They can be used to implement callbacks and event handlers.
Functors can be used to create custom comparators for sorting algorithms.
They can also be used to implement function objects for mathematical operations.
Examples of functors in C++ include std::function, st...read more
Q10. IPC mechanisms in Linux
IPC mechanisms in Linux are used for inter-process communication between processes running on the same system.
IPC mechanisms include pipes, message queues, shared memory, and semaphores.
Pipes are used for one-way communication between two processes.
Message queues allow for asynchronous communication between processes.
Shared memory allows multiple processes to access the same memory space.
Semaphores are used for synchronization between processes.
IPC mechanisms can be accessed ...read more
More about working at Western Digital
Reviews
Interviews
Salaries
Users/Month