Untitled

mail@pastecode.io avatar
unknown
typescript
8 months ago
600 B
9
Indexable
Never
function theTest2(matrix: number[][]): number {

	let doctorAndHospital = new Map<number, Set<number>>();

	for (var i = 0; i < matrix.length; i++) {
		for (var j = 0; j < matrix[i].length; j++) {

			let doctorId = matrix[i][j];
			//i is hotel id, j is day
			let hospitals = doctorAndHospital.get(doctorId) ?? new Set<number>()

			hospitals.add(i)
			doctorAndHospital.set(doctorId, hospitals)
		}
	}

	let result = 0;
	for (const [key, val] of doctorAndHospital) {
		result += val.size > 1 ? 1 : 0
	}

	return result
}


console.log(theTest2([[1, 1, 5, 2, 3], [4, 5, 6, 4, 3], [9, 4, 4, 1, 5]]))