Python Program To Get Minimum Elements For String Construction
Given a String, the task is to write a Python program to count the minimum elements required to form a string from list elements.
Input : test_list = [“geek”, “ring”, “sfor”, “ok”, “woke”], tar_str = “working”
Output : 2
Explanation : working can be formed using woke and ring.
Input : test_list = [“geek”, “ring”, “sfor”, “ok”, “woke”], tar_str = “workinggeek”
Output : 3
Explanation : workinggeek can be formed using woke, geek and ring.
In this, we iterate for a list of strings and form all size combinations, each combination is converted to set and checked to be forming target string using issubset(), if found, the loop is exited and the count is recorded.
The original list is : ['geek', 'ring', 'sfor', 'ok', 'woke'] The Minimum count elements for string : 2