diff --git a/src/my_project/interviews/top_150_questions_round_23/ex_11_h_index.py b/src/my_project/interviews/top_150_questions_round_23/ex_11_h_index.py new file mode 100644 index 00000000..2bc31b7a --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_23/ex_11_h_index.py @@ -0,0 +1,16 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def hIndex(self, citations: List[int]) -> int: + + citations.sort(reverse=True) + len_cit:int = len(citations) + answer:int = 0 + + for i in range(len_cit): + + if citations[i] >= i + 1: + answer = i + 1 + + return answer diff --git a/src/my_project/interviews_typescript/top_150_questions_round_23/ex_11_h_index.ts b/src/my_project/interviews_typescript/top_150_questions_round_23/ex_11_h_index.ts new file mode 100644 index 00000000..0d002863 --- /dev/null +++ b/src/my_project/interviews_typescript/top_150_questions_round_23/ex_11_h_index.ts @@ -0,0 +1,13 @@ +function hIndex(citations: number[]): number { + citations.sort((a, b) => b - a); + const lenCit: number = citations.length; + let answer: number = 0; + + for (let i = 0; i < lenCit; i++) { + if (citations[i] >= i + 1) { + answer = i + 1; + } + } + + return answer; +}; diff --git a/tests/test_150_questions_round_23/test_11_h_index_round_23.py b/tests/test_150_questions_round_23/test_11_h_index_round_23.py new file mode 100644 index 00000000..7550aeaf --- /dev/null +++ b/tests/test_150_questions_round_23/test_11_h_index_round_23.py @@ -0,0 +1,17 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_23\ +.ex_11_h_index import Solution + +class hIndexTestCase(unittest.TestCase): + + def test_h_index_test_1(self): + solution = Solution() + output = solution.hIndex(citations = [3,0,6,1,5]) + target = 3 + self.assertEqual(output, target) + + def test_h_index_test_2(self): + solution = Solution() + output = solution.hIndex(citations = [1,3,1]) + target = 1 + self.assertEqual(output, target) \ No newline at end of file