0

I have this string abcpdxypabcdc I like this

abc=2 //repeated number of times

p=2 //...

d=2 //...

xy=1 //...

c=1 //...

Since its length will be known. In function I will get pointer having pointing to abcpdxypabcdc string and length of string which in this case will be 13. I like algorithm for it. I have tried it but I like to know what will be the correct to proceeding to solving these problems if I like to do it with pointers. I need explanation how to solve these types of problems

I think I need to maintain some struct with index where the each pattern start and a number that contains number of times the pattern is found in string so far. Plus second loop to check each array of struct contains duplicated items. But I like to know what is the correct way of solving these coding examples.

user786
  • 3,902
  • 4
  • 40
  • 72
  • 1
    So you want to generate all permutations of sub-strings and determine the frequency of each? It applies some type of map of string to count. You can use the original string if you (store a pointer or offset, size) to express each permutation. – Allan Wind Apr 02 '21 at 12:24
  • @AllanWind `You can use the original string if you (store a pointer or offset, size) to express each permutation` can u please clarify this. and what do u meant by `map of string` – user786 Apr 02 '21 at 12:31
  • @AllanWind thanks for comment – user786 Apr 02 '21 at 12:33
  • A map is an abstract data structure that stores the relation between a key and a value. In your case, the key is the permutation (string) and the value is the count. You can implement a map with a hash table. Now, what I told you was you store the permutation, like "a" by malloc 2 bytes. An alternative implementation would be to store it has struct { unint8_t offset, uint8_t len } where offset is the offset into your original string so "a" would be stored as {0, 1}. – Allan Wind Apr 02 '21 at 12:42
  • @AllanWind basically I meant in question pattern containing consecutive chars like `abc` I don't want `abp` or `abd`, etc. its not permutations. I was wrong. look at my question – user786 Apr 03 '21 at 04:47

0 Answers0