Sort by

recency

|

2694 Discussions

|

  • + 0 comments

    I get a Runtime Error :( after all tests are passed. Anyone knows why does this happens?

  • + 0 comments
    function processData(input) {
    
        const inputLines = input.split('\n');
        
      
        const entryCount = parseInt(inputLines[0]);
        
        
        const phoneBook = {};
        
    
        for (let i = 1; i <= entryCount; i++) {
            const [name, phoneNumber] = inputLines[i].split(' ');
            phoneBook[name] = phoneNumber;
        }
        
        
        for (let i = entryCount + 1; i < inputLines.length; i++) {
            const queryName = inputLines[i];
            if (queryName) { // Check if there is a query
                if (phoneBook[queryName]) {
                    console.log(`${queryName}=${phoneBook[queryName]}`);
                } else {
                    console.log('Not found');
                }
            }
        }
    }
    
  • + 0 comments

    I'm trying to solve this in Go and all of my attempts are timing out on test cases 1 - 3, despite working on the sample input 0. I think it's the loop reading/handling the query names, but I don't know why. Some examples:

    // Using a Scanner to handle queries
    scanner := bufio.NewScanner(os.Stdin)
    for scanner.Scan() {
    	name := scanner.Text()
    	if phone, ok := addressBook[name]; !ok {
    		fmt.Println("Not found")
    	} else {
    		fmt.Printf("%s=%s\n", name, phone)
    	}
    }
    if err := scanner.Err(); err != nil {
    	log.Fatal(err)
    }
    
    // Using fmt.Scan to handle queries
    var query string
    for {
    	_, err := fmt.Scan(&query)
    	if err != nil {
    		if err == io.EOF {
    			break
    		}
    		log.Fatal(err)
    	}
    	if phone, ok := addressBook[query]; !ok {
    		fmt.Println("Not found")
    	} else {
    		fmt.Printf("%s=%s\n", query, phone)
    	}
    }
    
    // Reading all of STDIN then iterating over it
    stdin, err := io.ReadAll(os.Stdin)
    if err != nil {
    	log.Fatal(err)
    }
    
    queries := strings.Split(string(stdin), "\n")
    for _, name := range queries {
    	if phone, ok := addressBook[name]; !ok {
    		fmt.Println("Not found")
    	} else {
    		fmt.Printf("%s=%s\n", name, phone)
    	}
    }
    
  • + 0 comments

    STATUS: RUNTIME ERROR. ALL TESTS PASSED.

    N = int(input()) dicc = {}

    for i in range(N): name, number = input().split() dicc[name] = number

    for i in range(N): name = input() if name in dicc: print(name+ "=" + dicc[name]) else: print("Not found")

  • + 0 comments

    this is my solution, it works for sample test case 0, but why doesn't it works when i submit the solution, i'm using nodejs, anyone have any idea what did i do wrong?

    function processData(input) {
        //Enter your code here
        const entry = parseInt(input[0])
        const inputString = input.split('\n')
        let phoneBook = {}
        
        for (let i = 1; i <= entry; i++) {
          let items = inputString[i].split(' ');
          phoneBook[items[0]] = items[1]
        }
        
        for (let i = entry + 1; i < inputString.length; i++) {
          if (phoneBook[inputString[i]]) {
            console.log(`${inputString[i]}=${phoneBook[inputString[i]]}`)
          } else {
            console.log('Not found')
          }
        }
    }