> For the complete documentation index, see [llms.txt](https://jiwons-organization.gitbook.io/jiwon0995/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jiwons-organization.gitbook.io/jiwon0995/dev-note/index-8/240909.md).

# 240909

문제 : [카드 뭉치](https://school.programmers.co.kr/learn/courses/30/lessons/159994)\
난이도 : Lv.1

## 풀이

```javascript
function solution(cards1, cards2, goal) {
    let index1 = 0;  // cards1의 현재 인덱스
    let index2 = 0;  // cards2의 현재 인덱스
    
    // goal의 단어를 순서대로 확인
    for (let word of goal) {
        // cards1에서 단어를 사용해야 할 경우
        if (index1 < cards1.length && cards1[index1] === word) {
            index1++;  // cards1의 다음 단어로 이동
        }
        // cards2에서 단어를 사용해야 할 경우
        else if (index2 < cards2.length && cards2[index2] === word) {
            index2++;  // cards2의 다음 단어로 이동
        }
        // 둘 다 아닐 경우 목표 단어 배열을 만들 수 없음
        else {
            return "No";
        }
    }
    
    // 모든 단어가 성공적으로 사용되었을 경우
    return "Yes";
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://jiwons-organization.gitbook.io/jiwon0995/dev-note/index-8/240909.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
