If the API allows these many calls, you can use a multiprocessing.pool.Pool function and iterate through each page parallelly to reduce time. This should work:

Copyimport requests
from functools import partial
from multiprocessing.pool import Pool

def loop(page,year,r,per_page):

   r = requests.get('https://jsonmock.hackerrank.com/api/football_matches?year='+str(year)+'&page='+str(page)).json()
   try:
      for i in range(0, per_page):
         if int(r['data'][i]['team1goals']) == int(r['data'][i]['team2goals']):
            increase = 1
         else:
            increase = 0
   except:
      increase = 0
   
   return increase

if __name__ == "__main__":
    
   year = 2011
   draw = []
   r = requests.get('https://jsonmock.hackerrank.com/api/football_matches?year='+str(year)+'&page=1').json()
   total_pages = r['total_pages']
   per_page = r['per_page']
   pages = range(1, total_pages+1)
   pool = Pool()
   f = pool.map(partial(loop,year=year,r=r,per_page=per_page),pages)
   draw += f
   final = 0
   for x in draw:
      x = int(x)
      final += x

   print(final) #516
Answer from Prateek Jain on Stack Overflow
🌐
GitHub
github.com › aashahin › HackerRank-Certification-REST-API › blob › main › 2. REST API: Number of Drawn Matches.md
HackerRank-Certification-REST-API/2. REST API: Number of Drawn Matches.md at main · aashahin/HackerRank-Certification-REST-API
The task is to get the number of matches for a given year that ended in a draw. A match is drawn when both teams scored the same number of goals. To access a collection of matches played in a given year, perform an HTTP GET request to · ...
Author   aashahin
🌐
GitHub
github.com › saro-mano › Hackerrank-Rest-API
GitHub - saro-mano/Hackerrank-Rest-API: Solution for Hackerrank REST API Certification · GitHub
Python solution for Hackerrank REST API Certification (Intermediate)
Starred by 14 users
Forked by 9 users
Languages   Python
🌐
GitHub
github.com › Harika-BV › React-API-Intermediate-Hackerrank › blob › master › (REST API) Number of Drawn Matches.py
React-API-Intermediate-Hackerrank/(REST API) Number of Drawn Matches.py at master · Harika-BV/React-API-Intermediate-Hackerrank
Solutions for React API Hackerrank certification problems in Python - React-API-Intermediate-Hackerrank/(REST API) Number of Drawn Matches.py at master · Harika-BV/React-API-Intermediate-Hackerrank
Author   Harika-BV
🌐
Brainly
brainly.in › computer science › secondary school
REST API: Number of Drawn Matches In this challenge, the REST API contains information about football - Brainly.in
November 4, 2024 - This solution efficiently utilizes the API's filtering capability to avoid examining individual match objects, ensuring a timely response.
🌐
Gitbook
dailyjournal.gitbook.io › solutions › hackerrank-solutions › certify › rest-api-intermediate
Rest API (Intermediate) | HackerRank | Solutions
The function must return an integer denoting the number of matches in the given year that ended up in a draw. You can safely assume that no team ever scored more than 10 goals. ... Explanation The year is 2011.
🌐
GitHub
github.com › kaarthikraajan › rest-api-hackerrank
GitHub - kaarthikraajan/rest-api-hackerrank: This is a solution to the problem presented in the hackerrank problem.
This is a solution to the problem presented in the hackerrank problem. - kaarthikraajan/rest-api-hackerrank
Starred by 6 users
Forked by 2 users
Languages   Java 100.0% | Java 100.0%
Find elsewhere
🌐
Studocu
studocu.com › jadavpur university › information and coding theory › rest api timed assessment challenge: team goals & draw analysis
REST API Timed Assessment Challenge: Team Goals & Draw Analysis - Studocu
September 7, 2024 - import requests import json team = 'Barcelona' year = 2011 goals = 0 for tm in ['team1', 'team2']: url = 'jsonmock.hackerrank/api/football_matches?year=' +str(year)+ '&' +tm+ '=' +team+ '&page=1' response = requests('GET', url, headers={}, data={}) total_pages = json(response.text('utf8'))['total_pages'] for i in range(1, total_pages+1): url = 'jsonmock.hackerrank/api/football_matches?year=' +str(year)+ '&' +tm+ '=' +team+ '&page=' +str(i) response = requests('GET', url, headers={}, data={}) r = json(response.text('utf8')) r_data = r['data'] for record in r_data: goals += int(record[tm+'goals']) goals
🌐
CodeSandbox
codesandbox.io › s › hackerrank-rest-api-exercise-1-solution-6so4m0
Hackerrank rest api exercise 1 solution - CodeSandbox
August 16, 2022 - Hackerrank rest api exercise 1 solution by claurennt using @xioo/xios, axios, react, react-dom, react-scripts
Published   Aug 01, 2022
Author   claurennt
🌐
GitHub
github.com › sumantopal07 › Rest-API-Intermediate-Hackerrank-Test
GitHub - sumantopal07/Rest-API-Intermediate-Hackerrank-Test · GitHub
Solution : Only done with 10 GET requests by taking advantage of the constraint of maximum of 10 goals scored by any team. const fetch = require("node-fetch"); let goals=[]; for(let i=0;i<=10;i++) goals.push(i); let ans=0; async function ...
Starred by 36 users
Forked by 8 users
🌐
YouTube
youtube.com › watch
REST API Intermediate Certification #03 - YouTube
HackerRank All skills certifications Github Link https://github.com/tkssharma/hackerrank-full-stack/tree/master/Full Stack Certifications- https://github...
Published   December 13, 2021
Top answer
1 of 1
4

https.get is a callbacked function so await won't work. You should promisify it first like they did in this other SO question;

const https = require("https");                                      // only require this once

const getJSONAsync = url => new Promise((resolve, reject) => {       // define a function getJSONAsync which returns a Promise that wraps the https.get call, getJSONAsync is awaitable
  let req = https.get(url, res => {                                  // make the https.get request
    if(res.statusCode < 200 || res.statusCode >= 300) {              // if the status code is an error one
      return reject(new Error('statusCode=' + res.statusCode));      // reject and skip the rest
    }

    let body = [];                                                   // otherwise accumulate..
    res.on('data', chunk => body.push(chunk));                       // ..the data
    res.on('end', () => {                                            // on end                               
      try {
        body = JSON.parse(Buffer.concat(body).toString());           // try to JSON.parse the data
      } catch(e) {
        reject(e);                                                   // reject if an error occurs
      }
      resolve(body);                                                 // resolve the parsed json object otherwise
    });
  });

  req.on("error", error => reject(error));                           // reject if the request fails too (if something went wrong before the request is sent for example)
});

async function getNumDraws(year) {
  let result = 0;

  for(let goal = 0; goal < 11; goal++) {
    let data = await getJSONAsync(`https://jsonmock.hackerrank.com/api/football_matches?year=${year}&team1goals=${goal}&team2goals=${goal}`);
    result += data.total;
  }

  return result;
}

Note: getJSONAsync is not specific to getNumDraws, you can use it somewhere else if you need it, and since it returns a Promise you can either await it like getNumDraws does or use it with then/catch blocks like so:

getJSONAsync("url")
  .then(data => {
    // data is the parsed json returned by the request
  })
  .catch(error => {
    // the error message if something fails
  })
🌐
GitHub
github.com › Reterics › -Hackerrank-Rest-API
GitHub - Reterics/-Hackerrank-Rest-API: Javascript Solution for Hackerrank Intermediate Rest API
Javascript Solution for Hackerrank Intermediate Rest API · This repository includes solutions for 1. REST API: Total Goals by a Team, and 1. REST API: Number of Drawn Matches exam tasks.
Author   Reterics
🌐
Unm
unm.ge › tags › 7c8b39-rest-api-number-of-drawn-matches-hackerrank-solution
rest api number of drawn matches hackerrank solution
APIs work in much the same way except instead of the web browser asking for a webpage, the program asks for data. Python Conditional: Exercise-10 with Solution. On the HackerRank Coding environment, most of your programs require to read input and write the output using the Standard Input stream ...
🌐
GitHub
github.com › 3RB16 › Rest-API-Intermediate-hackerrank-solution › blob › main › getWinnerTotalGoals.py
Rest-API-Intermediate-hackerrank-solution/getWinnerTotalGoals.py at main · 3RB16/Rest-API-Intermediate-hackerrank-solution
Rest-API-Intermediate-hackerrank-solution. Contribute to 3RB16/Rest-API-Intermediate-hackerrank-solution development by creating an account on GitHub.
Author   3RB16
🌐
YouTube
youtube.com › watch
Hackerrank Certification REST APIs Certification (Football matches APIs) #hackerrank - YouTube
This Video is a part of playlist "Crack javascript Interviews"https://www.youtube.com/watch?v=ET3IiPLI-JI&list=PLIGDNOJWiL18kcjnrT0KT64bo-kOYyQUF&ab_channel=...
Published   May 16, 2023
🌐
HackerRank
hackerrank.com › skills-verification › rest_api_intermediate
Rest API Intermediate Certificate
Proficiency in MySQL, a critical aspect of database management, is evaluated through database design, SQL queries, normalization, and optimization techniques. Additionally, expertise in REST APIs, vital for modern web applications, is assessed in terms of RESTful principles, HTTP methods, authentication, and API design best practices.
🌐
GitHub
github.com › aashahin › HackerRank-Certification-REST-API
GitHub - aashahin/HackerRank-Certification-REST-API: This repo is not for cheating!
2. REST API: Number of Drawn Matches.md · View all files · This repo is not for cheating! hackerrank problem-solving · Activity · 1 star · 1 watching · 1 fork · Report repository · No releases published · No packages published ·
Author   aashahin