Reputation: 1658
If i have an array that contains some char such as [a,b,c]
and i have another array that contains the respective frequency of each char such as [2,1,1]
. I would like to now go through a linked list which has nodes which have some string to see if they also have the chars i have in my original array with same frequency.
My approach
I was thinking i need
One loop that will start at index 0
of original array and another loop inside that will check all nodes for that string and if my temp pointer hits null it means all of them have it and if not then they don't and i move on to the next one. However i am not sure how to quite implement this approach as i am very new to c and also i was wondering is it possible to do this in O(N)
TIME as my approach would be O(N2).
Sample Output: i apologize for the confusion
so if you have 3 nodes and each has a char array containing "nba" "tba" "rba"
the output should then return b a
. since both them appear equal number of times in each node.
Upvotes: 1
Views: 173
Reputation: 643
So you start both your char array and freqarray at index 0 and then check all the nodes for strings matching the same frequency of a character . I presume you use some kind of function to return frequency of particular char in a string . Also your problem requires you to go through all of the nodes hence O(N^2) is implied.
Upvotes: 1