आसान 0 हल किए गए 0% स्वीकृति

To-Do List

Keep a list of tasks: add them, mark them done, remove them and report what is still pending.

आप क्या सीखेंगे

  • Keep tasks with a title and a done flag
  • Find an item by title before changing it
  • Filter the items that are still pending

समस्या

अनुवाद दिखाएँ

A to-do app keeps tasks in a typed collection such as List<T>. Each task has a title and a done flag.

Start with an empty list and process the operations, each a command and a title (the title is everything after the first space):

  • add <title>: add a pending task at the end, unless a task with that title already exists.
  • done <title>: mark that task as done (no effect if it does not exist).
  • remove <title>: delete that task (no effect if it does not exist).

Implement todo_list(operations).

Input

operations: The operations. Titles may contain spaces and are compared exactly.

Output

Return the titles of the tasks that are not done, in the order they were added.

सीमाएँ

0 ≤ number of operations ≤ 10,000

Titles have 1 to 50 characters

उदाहरण

उदाहरण 1
इनपुट:
operations = ["add Buy milk", "add Write report", "done Buy milk", "add Call Ada"]

अपेक्षित आउटपुट:
expected = ["Write report", "Call Ada"]
इनपुट:
std::vector<std::string> operations = {"add Buy milk", "add Write report", "done Buy milk", "add Call Ada"};

अपेक्षित आउटपुट:
std::vector<std::string> expected = {"Write report", "Call Ada"};
इनपुट:
string[] operations = new string[] {"add Buy milk", "add Write report", "done Buy milk", "add Call Ada"};

अपेक्षित आउटपुट:
string[] expected = new string[] {"Write report", "Call Ada"};

व्याख्या

Buy milk is done, so only the other two remain, in the order they were added: ["Write report", "Call Ada"].

उदाहरण 2
इनपुट:
operations = ["add Gym", "add Gym", "remove Gym", "done Gym"]

अपेक्षित आउटपुट:
expected = []
इनपुट:
std::vector<std::string> operations = {"add Gym", "add Gym", "remove Gym", "done Gym"};

अपेक्षित आउटपुट:
std::vector<std::string> expected = {};
इनपुट:
string[] operations = new string[] {"add Gym", "add Gym", "remove Gym", "done Gym"};

अपेक्षित आउटपुट:
string[] expected = new string[] {};

व्याख्या

The second add is ignored because Gym already exists; removing it leaves nothing, and done on a missing task does nothing: [].

कैसे हल करें

पहले खुद कोशिश करें, फिर एक-एक करके संकेत खोलें।

संकेत 1

Store each task as a small record of title and done.

संकेत 2

Look a task up by its exact title before adding, completing or removing it.

संकेत 3

At the end keep only the tasks that are not done, in insertion order.

अपेक्षित जटिलता

O(n²) time, O(n) extra space

संदर्भ

यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।

दूसरों से सीखें

समुदाय समाधान

अभी तक कोई प्रकाशित समाधान नहीं। पहला साझा करने के लिए इस चुनौती को हल करें।