Codepath

Grecian Artifacts

U-nderstand

Understand what the interviewer is asking for by using test cases and questions about the problem.

  • Q
    • What is the desired outcome?
    • To find the list of artifacts common to both time periods.
    • What input is provided?
    • Two lists of strings, artifacts1 and artifacts2.

P-lan

Plan the solution with appropriate visualizations and pseudocode.

General Idea: Use sets to find the intersection of the two lists, which gives the common artifacts.

1) Convert `artifacts1` and `artifacts2` to sets.
2) Find the intersection of the two sets.
3) Convert the resulting set back to a list and return it.

⚠️ Common Mistakes

  • Not converting the sets back to a list before returning.

I-mplement

def find_common_artifacts(artifacts1, artifacts2):
    # Convert the lists to sets to find the intersection
    set1 = set(artifacts1)
    set2 = set(artifacts2)

    # Find common artifacts using set intersection
    common_artifacts = set1 & set2

    # Convert the result back to a list
    return list(common_artifacts)
Fork me on GitHub