Count Distinct Elements in Every Window of Size K in a Subarray

Given an array of size “n” and an integer “k” where k < n. Write a program to return the count of distinct elements in every subarray of size “k”.
For eg:
      int arr[] = {1,2,3,4,1,3,4} , window size k = 4
      For 1st window of size 4 (index 0-3) – subarray = {1,2,3,4}, distinct element = 4
      For 2nd window of size 4 (index 1-4) – subarray = {2,3,4,1}, distinct element = 4
      For 3rd window of size 4 (index 2-5) – subarray = {3,4,1,3}, distinct element = 3
      For 4th window of size 4 (index 3-6) – subarray = {4,1,3,4}, distinct element = 3

(more…)
Count Distinct Elements in Every Window of Size K in a Subarray Read More

Program to Find Duplicate Files in a File System

Given in a directory, we have to write a program to find duplicate files in the file system.
For eg:
Let’s assume we have following files and it’s content in the file system.

char files[][80][80] = {{"1.txt", "abcd"},
                        {"2.txt", "efgh"},
                        {"3.txt", "efgh"},
                        {"4.txt", "abcd"},
                        {"5.txt", "efgh"},
                        {"6.txt", "efgh"},
                        {"7.txt", "xyz"}

Based on above input, duplicate files are – “1.txt” and “4.txt”. “2.txt”, “3.txt”, “5.txt” and “6.txt” are also duplicate files.

(more…)
Program to Find Duplicate Files in a File System Read More