{"id":22962504,"url":"https://github.com/cs2219/python_interview_questions","last_synced_at":"2025-04-02T03:28:17.629Z","repository":{"id":261741573,"uuid":"882574394","full_name":"CS2219/Python_interview_questions","owner":"CS2219","description":"Python Interview Questions hackerrank","archived":false,"fork":false,"pushed_at":"2024-11-08T07:11:45.000Z","size":24,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-07T18:18:16.152Z","etag":null,"topics":["array","counting","duplicate","hackerrank-solutions","product","python","reverse"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CS2219.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-03T06:39:15.000Z","updated_at":"2024-11-08T07:14:06.000Z","dependencies_parsed_at":"2024-11-08T07:25:00.369Z","dependency_job_id":"e5f22f95-9f5b-4406-a381-5c7ec1e0f4e6","html_url":"https://github.com/CS2219/Python_interview_questions","commit_stats":null,"previous_names":["cs2219/python_interview_questions"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CS2219%2FPython_interview_questions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CS2219%2FPython_interview_questions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CS2219%2FPython_interview_questions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CS2219%2FPython_interview_questions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CS2219","download_url":"https://codeload.github.com/CS2219/Python_interview_questions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246749233,"owners_count":20827471,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","counting","duplicate","hackerrank-solutions","product","python","reverse"],"created_at":"2024-12-14T19:17:09.521Z","updated_at":"2025-04-02T03:28:17.604Z","avatar_url":"https://github.com/CS2219.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python_interview_Questions_Hackerrank\nPython Interview Questions Hackerrank\n\n**#Question1-Array Segment Reversal**\n**#Problem Statement:****\nGiven an integer array arr and a list of operations operations, each operation specifies a segment of arr to reverse. The operations list is a 2D integer array where each element operations[i] contains two integers:\n\noperations[i][0]: the starting index of the segment (inclusive).\noperations[i][1]: the ending index of the segment (inclusive).\nYour task is to reverse the specified segments of the array in the order they are given in operations and return the modified array.\n\n**#Explanation of the Code**\nThe function performOperations(arr, operations) takes an array and a list of operations. Each operation is a list containing two indices [left, right].\nFor each operation, it reverses the subarray from index left to right using Python slicing.\nThe test cases are then executed with their respective inputs, and the results are printed out.\n\n**Testcase1-Basic test case**\narr = [0, 1, 2, 3, 4]\noperations = [[1, 3]]\nExpected Output: [0, 3, 2, 1, 4]\nExplanation: Reverse the subarray from index 1 to 3, resulting in [0, 3, 2, 1, 4].\n**Testcase2-Multiple Reversals**\narr = [1, 2, 3, 4, 5]\noperations = [[1, 3], [0, 4]]\nExpected Output: [5, 4, 3, 2, 1]\nExplanation: First, reverse [2, 3, 4] to get [1, 4, 3, 2, 5]. Then reverse the entire array, resulting in [5, 4, 3, 2, 1].\n**Testcase3-Reverse Entire Array**\narr = [9, 8, 7, 6]\noperations = [[0, 3]]\nExpected Output: [6, 7, 8, 9]\nExplanation: Reverse the entire array from index 0 to 3.\n**Testcase4-Single Element Array**\narr = [42]\noperations = [[0, 0]]\nExpected Output: [42]\nExplanation: A single-element array remains unchanged regardless of the operation.\n**Testcase5-No Operations**\narr = [1, 2, 3]\noperations = []\nExpected Output: [1, 2, 3]\nExplanation: No operations, so the array remains unchanged.\n**Testcase6-Consecutive Segment Reversals**\narr = [1, 2, 3, 4, 5, 6]\noperations = [[1, 4], [2, 3]]\nExpected Output: [1, 5, 4, 3, 2, 6]\nExplanation: First reverse [2, 3, 4, 5] to get [1, 5, 4, 3, 2, 6], then reverse [4, 3], which does not change the array further.\n**Testcase7-Overlapping Reversals**\narr = [10, 20, 30, 40, 50, 60]\noperations = [[0, 2], [1, 4]]\nExpected Output: [30, 50, 40, 20, 10, 60]\nExplanation: First reverse [10, 20, 30] to get [30, 20, 10, 40, 50, 60], then reverse [20, 10, 40, 50] to obtain the final output.\n\n**Question2-Counting duplicate products**\n**Problem**\nGiven three arrays: name, price, and weight, each describing a list of products where:\n\nname[i] is the name of the product.\nprice[i] is the price of the product.\nweight[i] is the weight of the product.\nTwo products are considered duplicates if they have the same name, price, and weight. \nThe goal is to count the number of such duplicate products.\nExplanation of the Code\nThe function numDuplicates(name, price, weight) takes three arrays as input and uses a set to track unique products represented as tuples.\nEach product is represented as a tuple (name[i], price[i], weight[i]).\nIf a product tuple is already in the set, it is counted as a duplicate.\nThe function returns the total count of duplicate products.\n\n**Testcase1-Basic Test Case**\n\nInput: [\"ball\", \"bat\", \"glove\", \"glove\", \"glove\"], [2, 3, 1, 1, 1], [2, 5, 1, 1, 1]\nExpected Output: 1 duplicate (glove, 1, 1 appears twice)\nExplanation:\nWe have the following products:\nProduct 1: (\"ball\", 2, 2)\nProduct 2: (\"bat\", 3, 5)\nProduct 3: (\"glove\", 1, 1)\nProduct 4: (\"glove\", 1, 1) — Duplicate of Product 3\nProduct 5: (\"glove\", 1, 1) — Duplicate of Product 3\nProduct 3 is duplicated twice (Products 4 and 5), so we count them as duplicates.\n\n**Testcase2-No Duplicates**\n\nInput: [\"apple\", \"banana\", \"cherry\"], [5, 6, 7], [1, 2, 3]\nExpected Output: 0 duplicates\nExplanation:\nWe have the following products:\nProduct 1: (\"apple\", 5, 1)\nProduct 2: (\"banana\", 6, 2)\nProduct 3: (\"cherry\", 7, 3)\nAll products are unique in terms of name, price, and weight.\n\n**Testcase3-All Elements are Duplicates**\n\nInput: [\"pen\", \"pen\", \"pen\"], [1, 1, 1], [1, 1, 1]\nExpected Output: 2 duplicates\nExplanation:\nWe have the following products:\nProduct 1: (\"pen\", 1, 1)\nProduct 2: (\"pen\", 1, 1) — Duplicate of Product 1\nProduct 3: (\"pen\", 1, 1) — Duplicate of Product 1\nProduct 1 is duplicated twice (Products 2 and 3).\n\n**Testcase4-Single Product**\n\nInput: [\"notebook\"], [10], [5]\nExpected Output: 0 duplicates\nExplanation:\nWe only have one product:\nProduct 1: (\"notebook\", 10, 5)\nSince there's only one product, there can't be any duplicates.\n\n**Testcase5-Mixed Products with some duplicates**\n\nInput: [\"phone\", \"tablet\", \"phone\", \"tablet\", \"laptop\"], [500, 300, 500, 350, 800], [200, 150, 200, 150, 700]\nExpected Output: 1 duplicate (phone, 500, 200 appears twice)\nExplanation:\nWe have the following products:\nProduct 1: (\"phone\", 500, 200)\nProduct 2: (\"tablet\", 300, 150)\nProduct 3: (\"phone\", 500, 200) — Duplicate of Product 1\nProduct 4: (\"tablet\", 350, 150) — Not a duplicate (different price)\nProduct 5: (\"laptop\", 800, 700)\nProduct 1 is duplicated once (by Product 3).\n\n**Testcase6-Edge Case with large inputs (no duplicates)**\n\nInput: Names: [\"item0\", \"item1\", ..., \"item999\"], Prices: [0, 1, ..., 999], Weights: [0, 1, ..., 999]\nExpected Output: 0 duplicates\nExplanation:\nWe have 1000 unique products, each with distinct names, prices, and weights.\nSince all products have unique attributes, there are no duplicates.\n\n**Testcase7-Duplicate Names with different attributes**\n\nInput: [\"chair\", \"chair\", \"chair\"], [20, 20, 25], [5, 10, 5]\nExpected Output: 0 duplicates (all attributes are different)\nExplanation:\nWe have the following products:\nProduct 1: (\"chair\", 20, 5)\nProduct 2: (\"chair\", 20, 10) — Not a duplicate (different weight)\nProduct 3: (\"chair\", 25, 5) — Not a duplicate (different price)\nNone of the products are duplicates since the attributes are different.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcs2219%2Fpython_interview_questions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcs2219%2Fpython_interview_questions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcs2219%2Fpython_interview_questions/lists"}