Can someone help me with the code and algo?
Heap is nothing but a part of RAM. It is used only when you are trying to allocate a memory dynamically. So, Through "malloc" and "calloc" system call you can allocate a memory dynamically. So, When ever you allocating memory through 'malloc" and "calloc" memory has been given from Heap.
Example; if you want an integer array of 10 elements. then you will need 40bytes. (size of element (4) * total no of element (10))
#include<stdio.h> main() { int *p; p = (int*)malloc(40); // p = (int*)calloc(10,4); }
Say you are given two arrays where second array is duplicate with one missing element. What should be the best possible way to find that missing element - array1: [1,2,3,4,5,6,7] array2: [1,3,4,5,6,7]
Missing Element: 2