I have been given a list of folder structures like
path = [ "/home/User/Desktop/gfg/test",
"/home/User/Desktop/gfg/file",
"/home/User/Desktop/geeks/folders" ,
"/home/User/Desktop/../geeks/a/folders"]
and we have to find out the common subdirectory among all the file paths. For example output of the above path list should be "home/User".
Solution:
Approach1: Iterate through each folder path and get the matrix of words and then compare each column one by one. Wherever the column condition fails return the most recent string till that column.
Happy to see more solutions and approach to solve this question. Feel free to answer.