Given a list of intervals, remove all intervals that are covered by another interval in the list.
Interval [a,b) is covered by interval [c,d) if and only if c <= a and b <= d.
After doing so, return the number of remaining intervals.
 
Example 1:
Input: intervals = [[1,4],[3,6],[2,8]]
Output: 2
Explanation: Interval [3,6] is covered by [2,8], therefore it is removed.

Example 2:
Input: intervals = [[1,4],[2,3]]
Output: 1

Example 3:
Input: intervals = [[0,10],[5,12]]
Output: 2

Example 4:
Input: intervals = [[3,10],[4,10],[5,11]]
Output: 2

Example 5:
Input: intervals = [[1,2],[1,4],[3,4]]
Output: 1

 
Constraints:

1 <= intervals.length <= 1000
intervals[i].length == 2
0 <= intervals[i][0] < intervals[i][1] <= 10^5
All the intervals are unique.

Source: leetcode | Difficulty: MEDIUM
Tags: Sorting

Data structures

Starter code: class Solution:
    def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
        

Solutions:
class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals.sort(key=lambda x: (x[0], -x[1]))
		prev_end = result = 0
		for (_, end) in intervals:
			if end > prev_end:
				result += 1
				prev_end = end
		return result


class Solution:

	def removeCoveredIntervals(self, l: List[List[int]]) -> int:
		l.sort(reverse=True, key=lambda x: (x[1], -x[0]))
		n = len(l)
		c = n
		for i in range(n - 1):
			if l[i][0] <= l[i + 1][0] and l[i][1] >= l[i + 1][1]:
				l[i + 1] = l[i]
				c -= 1
		return c


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		from functools import cmp_to_key

		def cmp(a, b):
			if a[0] > b[0]:
				return 1
			if a[0] < b[0]:
				return -1
			if a[1] > b[1]:
				return -1
			return 1
		lis = []
		if len(intervals) == 1:
			return 1
		for (x, y) in intervals:
			lis.append((x, y))
		lis.sort(key=cmp_to_key(cmp))
		fin = []
		fin.append(list(lis[0]))
		for i in range(1, len(lis)):
			(currx, curry) = lis[i]
			flag = 0
			for j in range(len(fin)):
				if curry <= fin[j][1] and currx >= fin[j][0]:
					flag = 1
			if flag == 0:
				fin.append([currx, curry])
		return len(fin)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals.sort(key=lambda x: (x[0], -x[1]))
		covering = 0
		used = set()
		for (i, (si, ei)) in enumerate(intervals):
			for (sj, ej) in intervals[i + 1:]:
				if sj > ei:
					break
				if ej > ei:
					continue
				if (sj, ej) in used:
					continue
				used.add((sj, ej))
				covering += 1
		return len(intervals) - covering


class Tree:

	def __init__(self, val, left=None, right=None):
		self.val = val
		self.left = left
		self.right = right

	def __lt__(self, other):
		if self.val[0] < other.val[0]:
			return True
		elif self.val[0] > other.val[0]:
			return False
		elif self.val[1] > other.val[1]:
			return True
		else:
			return False

	def __le__(self, other):
		return self < other or self.val == other.val

	def __gt__(self, other):
		return not self <= other

	def __ge__(self, other):
		return not self < other

	def __eq__(self, other):
		return self <= other and self >= geother

	def __neq__(self, other):
		return not self == other

class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		tree = Tree(val=tuple(intervals[0]))
		for (x, y) in intervals[1:]:
			this = Tree((x, y))
			cursor = tree
			while True:
				if this < cursor:
					if cursor.left:
						cursor = cursor.left
					else:
						cursor.left = this
						break
				elif this > cursor:
					if cursor.right:
						cursor = cursor.right
					else:
						cursor.right = this
						break
				else:
					break
		buff = [tree]
		(count, last) = (0, None)
		while buff:
			while buff[-1].left:
				buff.append(buff[-1].left)
			while buff and (not buff[-1].right):
				this = buff.pop(-1)
				if count == 0:
					(count, last) = (1, this.val[1])
				elif this.val[1] > last:
					(count, last) = (count + 1, this.val[1])
			if buff:
				this = buff.pop(-1)
				if count == 0:
					(count, last) = (1, this.val[1])
				elif this.val[1] > last:
					(count, last) = (count + 1, this.val[1])
				buff.append(this.right)
		return count


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		for i in range(0, len(intervals) - 1):
			minel = intervals[i]
			minid = i
			for j in range(i + 1, len(intervals)):
				evl = intervals[j]
				if evl[0] < minel[0]:
					minel = evl
					minid = j
			(intervals[i], intervals[minid]) = (intervals[minid], intervals[i])
		c = 0
		prevl = intervals[0][0]
		prevh = intervals[0][1]
		for x in range(1, len(intervals)):
			curl = intervals[x][0]
			curh = intervals[x][1]
			if curh <= prevh:
				c = c + 1
				continue
			if curl == prevl:
				c = c + 1
				if curh > prevh:
					prevh = curh
				continue
			prevl = curl
			prevh = curh
		return len(intervals) - c


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		ordered_intervals = sorted(intervals, key=lambda x: (x[0], -x[1]))
		candidates = set()
		for i in range(len(intervals)):
			(curr_start, curr_end) = ordered_intervals[i]
			for j in range(i + 1, len(intervals)):
				(next_start, next_end) = ordered_intervals[j]
				if next_start >= curr_end:
					break
				if next_end <= curr_end:
					candidates.add(j)
		return len(intervals) - len(candidates)


import numpy as np

class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		copy_intervals = intervals[:]
		for (i, interval_1) in enumerate(copy_intervals):
			for interval_2 in copy_intervals[i + 1:]:
				if interval_1[0] >= interval_2[0] and interval_1[1] <= interval_2[1]:
					if interval_1 in intervals:
						intervals.remove(interval_1)
					break
				if interval_1[0] <= interval_2[0] and interval_1[1] >= interval_2[1]:
					if interval_2 in intervals:
						intervals.remove(interval_2)
		return len(intervals)


class Solution:

	def removeCoveredIntervals(self, arr: List[List[int]]) -> int:
		arr.sort(reverse=True)
		ans = 0
		n = len(arr)
		take = [1] * n
		for i in range(n - 1):
			for j in range(i + 1, n):
				if arr[i][0] >= arr[j][0] and arr[i][1] <= arr[j][1]:
					take[i] = 0
					break
		for i in range(n - 1, -1, -1):
			for j in range(i - 1, -1, -1):
				if arr[i][0] >= arr[j][0] and arr[i][1] <= arr[j][1]:
					take[i] = 0
					break
		return take.count(1)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals.sort(key=lambda interval: (interval[0], -interval[1]))
		length = len(intervals)
		start = 0
		removed = 0
		while start < length - 1:
			curr = start + 1
			while curr < length:
				if intervals[curr][0] != -1:
					if intervals[curr][0] >= intervals[start][0] and intervals[curr][1] <= intervals[start][1]:
						removed += 1
						intervals[curr][0] = -1
						intervals[curr][1] = -1
				curr += 1
			start += 1
		return length - removed


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals = sorted(intervals, key=lambda x: x[1])
		n = len(intervals)
		cnt = 0
		for i in intervals:
			for j in intervals:
				if j == i:
					continue
				if i[1] <= j[1] and i[0] >= j[0]:
					cnt += 1
					break
		return n - cnt


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals.sort(reverse=True)
		intervals.sort(key=lambda i: i[1])
		covered = set()
		for (i, (c, d)) in enumerate(intervals):
			for (a, b) in intervals[0:i]:
				if c <= a and b <= d:
					covered.add((a, b))
		return len(intervals) - len(covered)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:

		def overlap(interval1, interval2):
			if interval1[0] > interval2[0]:
				(interval1, interval2) = (interval2, interval1)
			return interval1[1] >= interval2[1]
		intervals.sort(key=lambda x: (x[0], -x[1]))
		print(intervals)
		count = 0
		res = [intervals[0]]
		for i in intervals[1:]:
			print((i, res[-1]))
			if not overlap(res[-1], i):
				res.append(i)
		return len(res)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		n = len(intervals)
		flag = [0] * n
		i = 0
		while i < n:
			j = i + 1
			while j < n:
				if flag[i] != 1:
					print((i, j, intervals[i], intervals[j]))
					if intervals[j][0] <= intervals[i][0] and intervals[i][1] <= intervals[j][1]:
						flag[i] = 1
					if intervals[i][0] <= intervals[j][0] and intervals[j][1] <= intervals[i][1]:
						flag[j] = 1
				j += 1
			i += 1
		return flag.count(0)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		new = sorted(intervals, key=lambda x: x[1] - x[0], reverse=True)
		ans = []
		for (i, v) in enumerate(new):
			flag = False
			for elem in new[:i]:
				if v[0] >= elem[0] and v[1] <= elem[1]:
					flag = True
			if flag == False:
				ans.append(v)
		return len(ans)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		removed = 0
		removedSet = set()
		for ind1 in range(len(intervals)):
			for ind2 in range(len(intervals)):
				if ind1 == ind2 or ind1 in removedSet:
					continue
				interval1 = intervals[ind1]
				interval2 = intervals[ind2]
				if interval1[0] >= interval2[0] and interval1[1] <= interval2[1]:
					removed += 1
					removedSet.add(ind1)
		return len(intervals) - removed


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		n = len(intervals)
		flag = [True for i in range(n)]
		ctr = n
		for i in range(n):
			for j in range(n):
				if i != j and flag[i] and flag[j]:
					(a, b) = intervals[i]
					(c, d) = intervals[j]
					if c <= a and b <= d:
						flag[i] = False
						ctr -= 1
					elif a <= c and d <= b:
						flag[j] = False
						ctr -= 1
		return ctr


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:

		def covered(a, b):
			return a[0] >= b[0] and a[1] <= b[1]
		deleted = set()
		for i in range(len(intervals)):
			for j in range(len(intervals)):
				if i != j and i not in deleted:
					if covered(intervals[i], intervals[j]):
						deleted.add(i)
		return len(intervals) - len(deleted)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		int_set = set((tuple(i) for i in intervals))
		for (i, (a, b)) in enumerate(intervals):
			for (c, d) in intervals[i + 1:]:
				if a <= c and d <= b and ((c, d) in int_set):
					int_set.remove((c, d))
				elif c <= a and b <= d and ((a, b) in int_set):
					int_set.remove((a, b))
		return len(int_set)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		covered = 0
		m = {}
		for [l, r] in intervals:
			if l not in m:
				m[l] = r
			else:
				m[l] = max(r, m[l])
				covered += 1
		a = []
		for i in m:
			a.append([i, m[i]])
		a.sort(key=lambda x: x[0])
		_c = set()
		for i in range(len(a)):
			for j in range(i + 1, len(a)):
				if a[j][1] <= a[i][1] and j not in _c:
					_c.add(j)
					covered += 1
		return len(intervals) - covered


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals.sort(key=lambda tup: tup[1] - tup[0], reverse=True)
		covered = set()
		for i in range(len(intervals)):
			(s, e) = intervals[i]
			for j in range(i + 1, len(intervals)):
				(s2, e2) = intervals[j]
				if s <= s2 and e2 <= e:
					covered.add(j)
		return len(intervals) - len(covered)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		l = len(intervals)
		a = [True] * l
		for i in range(l):
			for j in range(l):
				if i == j:
					continue
				if not a[i] or not a[j]:
					continue
				if intervals[i][0] <= intervals[j][0] and intervals[i][1] >= intervals[j][1]:
					a[j] = False
		return a.count(True)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals.sort(key=lambda x: (x[0], -x[1]))
		ans = len(intervals)
		i = 0
		while i < len(intervals):
			for j in range(i):
				if intervals[j][0] <= intervals[i][0] and intervals[j][1] >= intervals[i][1]:
					ans -= 1
					break
			i += 1
		return ans


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals = sorted(intervals, key=lambda k: (k[0], -k[1]))
		removed = set()
		i = 0
		while i < len(intervals) - 1:
			for j in range(i + 1, len(intervals)):
				if intervals[j][1] <= intervals[i][1] and j not in removed:
					removed.add(j)
			i += 1
		return len(intervals) - len(removed)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		n = len(intervals)
		intervals.sort(key=lambda x: (x[0], -x[1]))
		removeSet = set()
		for i in range(n):
			interval1 = intervals[i]
			for j in range(i + 1, n):
				interval2 = intervals[j]
				if interval2[0] >= interval1[1]:
					break
				if interval2[1] <= interval1[1]:
					removeSet.add(j)
		return n - len(removeSet)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		l = len(intervals)
		removed = set()
		intervals.sort(key=lambda i: (i[0], -i[1]))
		for i in range(l):
			for j in range(i + 1, l):
				if intervals[i][1] >= intervals[j][1]:
					removed.add(j)
		return l - len(removed)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		discarded = [False] * len(intervals)
		for i in range(len(intervals)):
			for j in range(len(intervals)):
				if i == j:
					continue
				if discarded[j]:
					continue
				if intervals[j][0] >= intervals[i][0] and intervals[j][1] <= intervals[i][1]:
					discarded[j] = True
		kount = 0
		for i in range(len(intervals)):
			if not discarded[i]:
				kount = kount + 1
		return kount


def checkCovered(a, b):
	if a[0] < b[0] or a[1] > b[1]:
		return False
	return True

class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		covered = [0] * len(intervals)
		for i in range(len(intervals) - 1):
			a = intervals[i]
			for j in range(i + 1, len(intervals)):
				b = intervals[j]
				if covered[i] == 0:
					if checkCovered(a, b):
						covered[i] = 1
				if covered[j] == 0:
					if checkCovered(b, a):
						covered[j] = 1
		return covered.count(0)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		i = 0
		j = 1
		while i < len(intervals) and j < len(intervals):
			if intervals[i][0] >= intervals[j][0] and intervals[i][1] <= intervals[j][1]:
				intervals.pop(i)
				(i, j) = (0, 1)
			elif intervals[i][0] <= intervals[j][0] and intervals[i][1] >= intervals[j][1]:
				intervals.pop(j)
				(i, j) = (0, 1)
			else:
				j += 1
			if j == len(intervals):
				i += 1
				j = i + 1
		return len(intervals)


class Solution:

	def isCovered(self, A, B):
		if A[0] <= B[0] and A[1] >= B[1]:
			return True
		return False

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		index = 0
		while index < len(intervals):
			delete = False
			i = intervals[index]
			for j in intervals:
				if intervals[index] == j:
					continue
				if self.isCovered(i, j):
					intervals.remove(j)
					index = -1
					break
				if self.isCovered(j, i):
					intervals.remove(i)
					index = -1
					break
			index += 1
		return len(intervals)


import numpy as np

class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		current_intervals = np.array(intervals)
		for interval in intervals:
			mask = np.logical_and(current_intervals[:, 0] >= interval[0], current_intervals[:, 1] <= interval[1])
			current_intervals = current_intervals[np.logical_not(mask)]
			if sum(mask):
				current_intervals = np.append(current_intervals, [interval], axis=0)
		return len(current_intervals)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		seen = set()
		n = len(intervals)
		for i in range(n):
			for j in range(n):
				if j == i or j in seen:
					continue
				(st1, ed1) = (intervals[i][0], intervals[i][1])
				(st2, ed2) = (intervals[j][0], intervals[j][1])
				if st1 <= st2 and ed2 <= ed1:
					seen.add(j)
		return n - len(seen)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals.sort()
		results = []
		max_end = float('-inf')
		for i in intervals:
			if i[1] > max_end:
				max_end = i[1]
				if len(results) == 0 or i[0] != results[-1][0]:
					results.append(i)
				else:
					results[-1] = i
			print(results)
		return len(results)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		I = len(intervals)
		count = 0
		covered = {}
		removed = {}
		for i in range(0, I):
			for j in range(0, I):
				if i == j:
					continue
				if j in removed or i in removed:
					continue
				if intervals[i][0] <= intervals[j][0] and intervals[i][1] >= intervals[j][1]:
					if (i, j) not in covered and (j, i) not in covered:
						count += 1
						covered[i, j] = 1
						covered[j, i] = 1
						removed[j] = j
		return len(intervals) - count


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		if len(intervals) < 2:
			return len(intervals)
		intervals.sort(key=lambda interval: interval[0])
		(start, idx) = (0, 1)
		removed = set()
		while start < len(intervals):
			if idx == len(intervals):
				start += 1
				idx = start + 1
				continue
			if idx in removed:
				idx += 1
				continue
			if intervals[start][1] < intervals[idx][0]:
				start += 1
				idx = start + 1
				continue
			if intervals[start][1] >= intervals[idx][1]:
				removed.add(idx)
				idx += 1
				continue
			if intervals[start][1] <= intervals[idx][1]:
				if intervals[start][0] == intervals[idx][0]:
					removed.add(start)
					start = idx
				idx += 1
		return len(intervals) - len(removed)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		covered = set()
		for i in range(len(intervals) - 1):
			(a1, b1) = intervals[i]
			for j in range(i + 1, len(intervals)):
				(a2, b2) = intervals[j]
				if a2 <= a1 and b1 <= b2:
					covered.add(i)
				elif a1 <= a2 and b2 <= b1:
					covered.add(j)
		return len(intervals) - len(covered)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		N = len(intervals)
		intervals.sort(key=lambda x: x[0])
		count = 0
		covered = set()
		for i in range(N):
			for j in range(N):
				if i != j and j not in covered:
					min_x = min(intervals[i][0], intervals[j][0])
					max_y = max(intervals[i][1], intervals[j][1])
					if intervals[i] == [min_x, max_y]:
						covered.add(j)
						count += 1
		return N - count


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		lis = intervals
		arr = []
		lis.sort()
		for i in range(0, len(lis)):
			if lis[i] in arr:
				continue
			for j in range(i + 1, len(lis)):
				if i < len(lis) and j < len(lis):
					if lis[i][0] >= lis[j][0] and lis[i][1] <= lis[j][1] and (lis[i] not in arr):
						arr.append(lis[i])
					if lis[i][0] <= lis[j][0] and lis[i][1] >= lis[j][1] and (lis[j] not in arr):
						arr.append(lis[j])
				else:
					break
		return len(lis) - len(arr)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		n = len(intervals)
		for i in range(n):
			for j in range(i + 1, n):
				if intervals[i][0] > intervals[j][0]:
					(intervals[i], intervals[j]) = (intervals[j], intervals[i])
		l = [intervals[0]]
		for i in range(1, n):
			if intervals[i][0] >= l[-1][0] and intervals[i][1] <= l[-1][1]:
				intervals[i] = -1
			elif intervals[i][0] <= l[-1][0] and intervals[i][1] >= l[-1][1]:
				intervals[i - 1] = -1
			if intervals[i] != -1:
				l.append(intervals[i])
		print(intervals)
		return n - intervals.count(-1)


from functools import cmp_to_key

class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:

		def cmp_intervals(left, right):
			if left[0] == right[0]:
				return right[1] - left[1]
			return left[0] - right[0]
		n = len(intervals)
		s_intervals = sorted(intervals, key=cmp_to_key(cmp_intervals))
		covered = set()
		for i in range(n - 1):
			(a, b) = s_intervals[i]
			for j in range(i + 1, n):
				(c, d) = s_intervals[j]
				if a <= c and d <= b:
					covered.add((c, d))
		return n - len(covered)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals.sort()
		drop = set([])
		for i in range(len(intervals)):
			(x, y) = intervals[i]
			for j in range(i + 1, len(intervals)):
				(a, b) = intervals[j]
				if x >= a and y <= b:
					drop.add(i)
					break
				elif a >= x and b <= y:
					drop.add(j)
		return len(intervals) - len(drop)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		n = len(intervals)
		intervals.sort(reverse=True)
		temp = []
		for i in range(n - 1, -1, -1):
			for k in range(0, n):
				if i != k and (intervals[k][0] <= intervals[i][0] and intervals[i][1] <= intervals[k][1]):
					temp.append(intervals[i])
					break
		res = [i for i in intervals if i not in temp]
		return len(res)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals.sort(key=lambda t: [t[0], t[1]])
		deleted = set()
		i = 0
		while i < len(intervals):
			boundary = tuple(intervals[i])
			if not boundary in deleted:
				j = i + 1
				stop = False
				while not stop and j < len(intervals):
					comparedBoundary = tuple(intervals[j])
					if comparedBoundary[0] == boundary[0]:
						deleted.add(boundary)
						stop = True
					elif comparedBoundary[0] >= boundary[1]:
						stop = True
					elif comparedBoundary[1] <= boundary[1]:
						deleted.add(comparedBoundary)
					j += 1
			i += 1
		return len(intervals) - len(deleted)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		for i in range(len(intervals)):
			for j in range(i, len(intervals)):
				if i == j or type(intervals[i][0]) == str or type(intervals[j][0]) == str:
					continue
				elif intervals[i][0] >= intervals[j][0] and intervals[i][1] <= intervals[j][1]:
					intervals[i] = ['', '']
				elif intervals[j][0] >= intervals[i][0] and intervals[j][1] <= intervals[i][1]:
					intervals[j] = ['', '']
		interval = []
		for ele in intervals:
			if ele != ['', '']:
				interval.append(ele)
		return len(interval)


from collections import defaultdict

class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		n = len(intervals)
		m = n
		visited = defaultdict(lambda : False)
		for i in range(n):
			for j in range(n):
				if i == j or visited[j]:
					continue
				if intervals[i][0] <= intervals[j][0]:
					if intervals[i][1] >= intervals[j][1]:
						visited[j] = True
						m -= 1
		return m


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		n = len(intervals)
		removed = [False] * n
		intervals = sorted(intervals, key=lambda interval: (interval[0], -interval[1]))
		for i in range(len(intervals)):
			(start, end) = intervals[i]
			j = i + 1
			while j < len(intervals) and end >= intervals[j][0]:
				if end >= intervals[j][1] and (not removed[j]):
					removed[j] = True
					n -= 1
				j += 1
		return n


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		n = len(intervals)
		flags = []
		for i in range(n):
			flags.append(0)
		k = n
		for i in range(n):
			for j in range(n):
				if i == j or flags[j] == 1:
					continue
				if intervals[i][0] <= intervals[j][0] and intervals[i][1] >= intervals[j][1]:
					flags[j] = 1
					k -= 1
		return k


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		L = len(intervals)
		discard = set()
		for i in range(L):
			(x, y) = intervals[i]
			for j in range(i + 1, L):
				(a, b) = intervals[j]
				if a <= x and b >= y:
					discard.add((x, y))
				elif x <= a and y >= b:
					discard.add((a, b))
		return L - len(discard)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		length = len(intervals)
		if length <= 1:
			return length
		temp = intervals[:]
		(i, j) = (0, 1)
		while i < len(intervals) - 1:
			j = i + 1
			while j < len(intervals):
				if self.ainbHelper(intervals[i], intervals[j]) == True:
					try:
						temp.remove(intervals[i])
					except:
						pass
					break
				elif self.ainbHelper(intervals[j], intervals[i]) == True:
					try:
						temp.remove(intervals[j])
					except:
						pass
					j += 1
				else:
					j += 1
			i += 1
		return len(temp)

	def ainbHelper(self, a: List[int], b: List[int]) -> bool:
		if a[0] < b[0]:
			return False
		if a[1] > b[1]:
			return False
		else:
			return True


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		for i in range(len(intervals)):
			for j in range(len(intervals)):
				if i != j:
					if intervals[i] != 0 and intervals[j] != 0:
						if intervals[j][0] <= intervals[i][0] and intervals[i][1] <= intervals[j][1]:
							intervals[i] = 0
		c = 0
		for i in intervals:
			if i != 0:
				c += 1
		return c


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		s = set()
		for (i, [a, b]) in enumerate(intervals):
			for (j, [c, d]) in enumerate(intervals[i + 1:]):
				if c <= a and b <= d:
					s.add((a, b))
				elif a <= c and d <= b:
					s.add((c, d))
		return len(intervals) - len(s)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		for i in range(len(intervals) - 1):
			for j in range(len(intervals) - i - 1):
				if intervals[j][0] > intervals[j + 1][0]:
					(intervals[j], intervals[j + 1]) = (intervals[j + 1], intervals[j])
		i = 0
		while True:
			while intervals[i][1] >= intervals[i + 1][1]:
				intervals.pop(i + 1)
				if i + 1 > len(intervals) - 1:
					break
			if i + 1 > len(intervals) - 1:
				break
			if intervals[i][0] == intervals[i + 1][0]:
				intervals.pop(i)
				if i + 1 > len(intervals) - 1:
					break
				else:
					continue
			if i + 1 == len(intervals) - 1:
				break
			i += 1
		return len(intervals)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		op = 0
		if len(intervals) < 2:
			return len(intervals)
		intervals.sort(key=lambda l1: l1[0])
		for j in intervals:
			for k in intervals:
				if j[0] != k[0] or j[1] != k[1]:
					if j[0] >= k[0] and j[1] <= k[1]:
						op += 1
						break
		return len(intervals) - op


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		sorted_intervals = sorted(intervals, key=lambda x: (x[0], -x[1]))
		covered = [False for interval in intervals]
		print(sorted_intervals)
		for (outer_index, outer) in enumerate(sorted_intervals):
			for (inner_index, inner) in enumerate(sorted_intervals[outer_index + 1:]):
				if outer[0] <= inner[0] and outer[1] >= inner[1]:
					covered[inner_index + outer_index + 1] = True
		print(covered)
		return sum((not cover for cover in covered))


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		L = len(intervals)
		rm = set()
		for i in range(L):
			for j in range(i + 1, L):
				(l1, r1) = intervals[i]
				(l2, r2) = intervals[j]
				if l1 <= l2 and r1 >= r2:
					if j not in rm:
						rm.add(j)
				elif l1 >= l2 and r1 <= r2:
					if i not in rm:
						rm.add(i)
		return L - len(rm)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		count = [0] * len(intervals)
		for i in range(len(intervals) - 1):
			a = intervals[i][0]
			b = intervals[i][1]
			for j in range(i + 1, len(intervals)):
				x = intervals[j][0]
				y = intervals[j][1]
				if x <= a and b <= y:
					count[i] = 1
				elif a <= x and y <= b:
					count[j] = 1
		ans = 0
		for c in count:
			if c == 0:
				ans += 1
		return ans


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		rm = {}
		for i in range(1, len(intervals)):
			for ((a, b), (c, d)) in zip(intervals[0:-i], intervals[i:]):
				if a >= c:
					if b <= d:
						rm[a, b] = True
				elif c >= a:
					if d <= b:
						rm[c, d] = True
		return len(intervals) - len(rm)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		n = len(intervals)
		for i in range(n - 1):
			for j in range(i + 1, n):
				if intervals[i][0] > intervals[j][0]:
					(intervals[i], intervals[j]) = (intervals[j], intervals[i])
				elif intervals[i][0] == intervals[j][0]:
					if intervals[i][1] < intervals[j][1]:
						(intervals[i], intervals[j]) = (intervals[j], intervals[i])
		l = []
		print(intervals)
		for i in intervals:
			if l == []:
				l.append(i)
			else:
				k1 = l[-1]
				k2 = i
				if k1[0] <= k2[0] and k1[1] >= k2[1]:
					continue
				else:
					l.append(i)
		return len(l)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		cover = [False for i in range(len(intervals))]
		for i in range(len(intervals)):
			for j in range(i + 1, len(intervals)):
				(a, b) = intervals[i]
				(c, d) = intervals[j]
				if c <= a and b <= d:
					cover[i] = True
				if a <= c and d <= b:
					cover[j] = True
		ans = []
		print(cover)
		for i in range(len(cover)):
			if not cover[i]:
				ans.append(intervals[i])
		return len(ans)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		toremove = set()
		for i in range(0, len(intervals) - 1):
			for j in range(i + 1, len(intervals)):
				(s1, e1) = intervals[i]
				(s2, e2) = intervals[j]
				if s1 >= s2 and e1 <= e2:
					toremove.add(i)
				elif s2 >= s1 and e2 <= e1:
					toremove.add(j)
		return len(intervals) - len(toremove)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:

		def comparator(a, b):
			return a[0] - b[0]
		intervals.sort()
		removed = {}
		for (index, interval) in enumerate(intervals):
			for (inner_index, inner_interval) in enumerate(intervals):
				if index == inner_index:
					continue
				if index in removed or inner_index in removed:
					continue
				if inner_interval[0] >= interval[0] and inner_interval[1] <= interval[1]:
					removed[inner_index] = True
		return len(intervals) - len(removed.keys())


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		tot = len(intervals)
		valid = [True] * len(intervals)
		for i in range(len(intervals)):
			if valid[i]:
				for j in range(len(intervals)):
					if i == j:
						continue
					if valid[j] and intervals[j][0] >= intervals[i][0] and (intervals[j][1] <= intervals[i][1]):
						valid[j] = False
						tot -= 1
		return tot


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		removed = []
		for i in range(len(intervals) - 1):
			for j in range(i + 1, len(intervals)):
				if i in removed:
					break
				if j in removed:
					continue
				(i_start, i_end) = intervals[i]
				(j_start, j_end) = intervals[j]
				if i_start <= j_start and i_end >= j_end:
					removed.append(j)
				elif i_start >= j_start and i_end <= j_end:
					removed.append(i)
		return len(intervals) - len(removed)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		if not intervals:
			return 0
		count = 0
		for (i, [left, right]) in enumerate(intervals):
			flag = True
			for (j, [oleft, oright]) in enumerate(intervals):
				if oleft <= left and right <= oright and (i != j):
					flag = False
					continue
			if flag:
				count += 1
		return count


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals = sorted(intervals, key=lambda x: (x[0], -x[1]))
		if len(intervals) == 1:
			return 1
		remove_indices = []
		for (p1, (l1, r1)) in enumerate(intervals[:-1]):
			for (p2, (l2, r2)) in enumerate(intervals[p1 + 1:]):
				if l1 <= l2 and r1 >= r2:
					remove_indices.append(p2 + p1)
				elif l1 < l2 < r1:
					continue
				else:
					break
		return len([interval for (idx, interval) in enumerate(intervals) if idx not in remove_indices])


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		n = len(intervals)
		ref = [1] * n
		for i in range(n):
			for j in range(n):
				if i == j or not ref[i] & ref[j]:
					continue
				if intervals[i][0] <= intervals[j][0] and intervals[i][1] >= intervals[j][1]:
					ref[j] = 0
		return sum(ref)


from copy import deepcopy

class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intind = []
		for i in range(0, len(intervals)):
			a = intervals[i][0]
			b = intervals[i][1]
			for j in range(i + 1, len(intervals)):
				c = intervals[j][0]
				d = intervals[j][1]
				if c <= a and b <= d:
					intind.append(i)
				if a <= c and d <= b:
					intind.append(j)
		return len(intervals) - len(set(intind))


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		exclusion_set = set()
		for i in range(len(intervals)):
			for j in range(i + 1, len(intervals)):
				(a, b) = intervals[i]
				(c, d) = intervals[j]
				if c <= a and b <= d:
					exclusion_set.add((a, b))
				if a <= c and d <= b:
					exclusion_set.add((c, d))
		return len(intervals) - len(exclusion_set)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		exclude = list()
		for (ind, left) in enumerate(intervals[:-1]):
			if left in exclude:
				continue
			for right in intervals[ind + 1:]:
				if right in exclude:
					continue
				elif right[0] <= left[0] and left[1] <= right[1]:
					exclude.append(left)
					break
				elif left[0] <= right[0] and right[1] <= left[1]:
					exclude.append(right)
				else:
					continue
		return len(intervals) - len(exclude)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		removed = []
		for (i, interval) in enumerate(intervals):
			for i2 in range(i, len(intervals)):
				interval2 = intervals[i2]
				if i in removed:
					break
				if i == i2 or i2 in removed:
					continue
				if interval[0] >= interval2[0] and interval[1] <= interval2[1] and (i not in removed):
					removed += [i]
				if interval[0] <= interval2[0] and interval[1] >= interval2[1] and (i2 not in removed):
					removed += [i2]
		return len(intervals) - len(removed)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		total = len(intervals)
		for (i, inner) in enumerate(intervals):
			for (o, outer) in enumerate(intervals):
				if outer[0] <= inner[0] and outer[1] >= inner[1] and (i != o):
					total -= 1
					break
		return total


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		counter = 0
		l = len(intervals)
		for i in range(l):
			for j in range(l):
				if i != j:
					if intervals[j][0] <= intervals[i][0] and intervals[i][1] <= intervals[j][1]:
						counter += 1
						break
		return l - counter


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals.sort(key=lambda x: (x[0], -x[1]))
		intervals = list(map(tuple, intervals))
		covered = set()
		for (i, iv) in enumerate(intervals):
			if iv in covered:
				continue
			for iv2 in intervals[i + 1:]:
				if iv2[0] > iv[1]:
					break
				if iv[0] <= iv2[0] and iv[1] >= iv2[1]:
					print(iv2)
					covered.add(iv2)
		return len(intervals) - len(covered)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		op = 0
		if len(intervals) < 2:
			return len(intervals)
		for j in intervals:
			for k in intervals:
				if j[0] != k[0] or j[1] != k[1]:
					if j[0] >= k[0] and j[1] <= k[1]:
						op += 1
						break
		return len(intervals) - op


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		arr = []
		for val in intervals:
			for interval in intervals:
				if interval[0] == val[0] and interval[1] == val[1]:
					continue
				if interval[0] <= val[0] and interval[1] >= val[1]:
					break
			else:
				arr.append(val)
		return len(arr)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		i = 0
		result = len(intervals)
		while i < len(intervals) - 1:
			(a1, b1) = intervals[i]
			j = i + 1
			remove_i = False
			while j < len(intervals):
				(a2, b2) = intervals[j]
				if a2 >= a1 and b2 <= b1:
					intervals = intervals[:j] + intervals[j + 1:]
					result -= 1
					continue
				if a1 >= a2 and b1 <= b2:
					intervals = intervals[:i] + intervals[i + 1:]
					result -= 1
					remove_i = True
					break
				j = j + 1
			if remove_i:
				continue
			i += 1
		return result


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		ans = 0
		for i in range(len(intervals)):
			canFit = False
			for j in range(len(intervals)):
				if i == j:
					continue
				if intervals[i][0] >= intervals[j][0] and intervals[i][1] <= intervals[j][1]:
					canFit = True
					break
			if canFit == False:
				ans += 1
		return ans


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		for i in range(len(intervals) - 1):
			if intervals[i][0] == -1:
				continue
			for j in range(i + 1, len(intervals)):
				t = intervals[i]
				tn = intervals[j]
				if t[0] <= tn[0] and tn[1] <= t[1]:
					(intervals[j][0], intervals[j][1]) = (-1, -1)
				elif tn[0] <= t[0] and t[1] <= tn[1]:
					(intervals[i][0], intervals[i][1]) = (-1, -1)
		count = 0
		for i in intervals:
			if i[0] != -1:
				count += 1
		return count


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		n_intervals = len(intervals)
		if intervals:
			intervals = sorted(intervals, key=lambda x: x[0] - x[1])
			i = len(intervals) - 1
			while i > 0:
				interval_i = intervals[i]
				j = i - 1
				while j >= 0:
					if intervals[j][0] <= interval_i[0] and intervals[j][1] >= interval_i[1]:
						n_intervals -= 1
						break
					j -= 1
				i -= 1
		return n_intervals


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		cov = 0

		def covered(first, second):
			return first[0] <= second[0] and second[1] <= first[1]
		for (pos, inter1) in enumerate(intervals):
			for (checkpos, inter2) in enumerate(intervals):
				if pos != checkpos and covered(inter2, inter1):
					cov += 1
					break
		return len(intervals) - cov


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		count = len(intervals)
		for i in range(len(intervals)):
			for j in range(len(intervals)):
				if (i != j) & (intervals[i][0] >= intervals[j][0]) & (intervals[i][1] <= intervals[j][1]):
					count = count - 1
					break
		return count


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		covered = 0
		same = 0
		for i in range(len(intervals)):
			for j in range(len(intervals)):
				if intervals[i][0] == intervals[j][0] and intervals[j][1] == intervals[i][1]:
					continue
				elif intervals[i][0] >= intervals[j][0] and intervals[j][1] >= intervals[i][1]:
					covered += 1
					break
		return len(intervals) - covered


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		return self.m1_sort(intervals)

	def m1_sort(self, intervals):
		intervals.sort(key=lambda x: x[1], reverse=True)
		intervals.sort(key=lambda x: x[0])
		count = 0
		max_end = 0
		for interval in intervals:
			if interval[1] > max_end:
				max_end = interval[1]
				count += 1
		return count


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		a = self.checkInterval(intervals)
		return len(a)

	def checkInterval(self, intervals) -> List[List[int]]:
		if len(intervals) == 1:
			return [intervals[0]]
		else:
			front = intervals[0]
			back = self.checkInterval(intervals[1:])
			if not back:
				return front
			(s, e) = (front[0], front[1])
			irrelevant = list([interval for interval in back if interval[0] <= s and e <= interval[1]])
			if len(irrelevant):
				return back
			filtered = list([interval for interval in back if not (s <= interval[0] and interval[1] <= e)])
			return [front] + filtered


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals.sort(key=lambda x: (x[0], -x[1]))
		q = [intervals[0][1]]
		counter = 0
		for (a, b) in intervals[1:]:
			t = [x for x in q]
			flag = 0
			for v in q:
				if a > v:
					t.remove(v)
					flag = 1
				elif b <= v:
					counter += 1
					break
				else:
					flag = 1
			if flag == 1:
				t.append(b)
			q = t
		return len(intervals) - counter


class Solution:

	def checkIntvl(self, a: List[int], b: List[int]) -> bool:
		return b[0] <= a[0] and b[1] >= a[1]

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		count = 0
		for (i, i1) in enumerate(intervals):
			is_covered = False
			for (j, i2) in enumerate(intervals):
				if i == j:
					continue
				else:
					is_covered = self.checkIntvl(i1, i2)
					if is_covered:
						break
			if not is_covered:
				count += 1
		return count


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals.sort(key=lambda interval: interval[1] - interval[0])
		counter = 0
		i = 0
		n = len(intervals)
		for i in range(n):
			covered = False
			for j in range(i + 1, n):
				if self.cover(intervals[j], intervals[i]):
					covered = True
					break
			if not covered:
				counter += 1
		return counter

	def cover(self, interval1, interval2):
		return interval1[0] <= interval2[0] and interval1[1] >= interval2[1]


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		covered = set()
		p1 = 0
		while p1 < len(intervals):
			if p1 in covered:
				p1 += 1
				continue
			p2 = p1 + 1
			while p2 < len(intervals):
				if intervals[p1][0] <= intervals[p2][0] and intervals[p2][1] <= intervals[p1][1]:
					covered.add(p2)
				elif intervals[p2][0] <= intervals[p1][0] and intervals[p1][1] <= intervals[p2][1]:
					covered.add(p1)
				p2 += 1
			p1 += 1
		return len(intervals) - len(covered)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:

		def covers(interval, byinterval):
			return interval[0] >= byinterval[0] and interval[1] <= byinterval[1]
		ret = 0
		for i in range(len(intervals)):
			iscovered = False
			for j in (x for x in range(len(intervals)) if x != i):
				if covers(intervals[i], intervals[j]):
					iscovered = True
					break
			if not iscovered:
				ret += 1
		return ret


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		deleted = set()
		for (idx, interval) in enumerate(intervals):
			if str(interval) in deleted:
				continue
			for other in intervals[idx + 1:]:
				if interval[0] <= other[0] and interval[1] >= other[1]:
					deleted.add(str(other))
				elif interval[0] >= other[0] and interval[1] <= other[1]:
					deleted.add(str(interval))
		return len(intervals) - len(deleted)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals.sort(key=lambda x: (x[0], -x[1]))
		ub = [x[1] for x in intervals]
		d = [x - max(ub[:i + 1]) <= 0 for (i, x) in enumerate(ub[1:])]
		return len(intervals) - sum(d)


class Solution:

	def compare(self, intervalA: List[int], intervalB: List[int]) -> int:
		if intervalA[0] <= intervalB[0] and intervalA[1] >= intervalB[1]:
			return 1
		if intervalB[0] <= intervalA[0] and intervalB[1] >= intervalA[1]:
			return -1
		return 0

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals.sort(key=lambda x: x[0])
		result = len(intervals)
		index = 0
		while index < len(intervals):
			itemA = intervals[index]
			removes = []
			for i in range(index + 1, len(intervals)):
				itemB = intervals[i]
				comp = self.compare(itemA, itemB)
				if comp == 0:
					continue
				if comp == 1:
					removes.append(i)
				elif comp == -1 and index not in removes:
					removes.append(index)
			if len(removes) == 0:
				index += 1
			else:
				removes.sort()
				removes.reverse()
				for k in range(len(removes)):
					intervals.remove(intervals[removes[k]])
				if index not in removes:
					index += 1
			result -= len(removes)
		return result


class Solution:

	def removeCoveredIntervals(self, intervals):
		result = 0
		for i in range(len(intervals)):
			covered = False
			for j in range(len(intervals)):
				if i == j:
					continue
				if self.covered(intervals[i], intervals[j]):
					covered = True
					break
			if not covered:
				result += 1
		return result

	def covered(self, i1, i2):
		c = i2[0]
		d = i2[1]
		a = i1[0]
		b = i1[1]
		return c <= a and b <= d


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		sorted_intervals = sorted(intervals, key=lambda x: (x[0], -x[1]))
		new_intervals = []
		new_intervals.append(sorted_intervals[0])
		for i in sorted_intervals:
			n = new_intervals[-1]
			if i[0] >= n[0] and i[1] <= n[1]:
				continue
			new_intervals.append(i)
		return len(new_intervals)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		tree = {}
		for (x, y) in intervals:
			cursor = tree
			if not tree:
				tree['value'] = (x, y)
			else:
				while True:
					if x < cursor['value'][0]:
						tmp = cursor.get('left', {})
						if tmp:
							cursor = tmp
						else:
							cursor['left'] = {'value': (x, y)}
							break
					elif x > cursor['value'][0]:
						tmp = cursor.get('right', {})
						if tmp:
							cursor = tmp
						else:
							cursor['right'] = {'value': (x, y)}
							break
					elif y > cursor['value'][1]:
						tmp = cursor.get('left', {})
						if tmp:
							cursor = tmp
						else:
							cursor['left'] = {'value': (x, y)}
							break
					elif y < cursor['value'][1]:
						tmp = cursor.get('right', {})
						if tmp:
							cursor = tmp
						else:
							cursor['right'] = {'value': (x, y)}
							break
					else:
						break
		buff = [tree]
		(count, last) = (0, None)
		while buff:
			while buff[-1].get('left', None):
				buff.append(buff[-1]['left'])
			while buff and (not buff[-1].get('right', None)):
				this = buff.pop(-1)
				if count == 0:
					(count, last) = (1, this['value'][1])
				elif this['value'][1] > last:
					(count, last) = (count + 1, this['value'][1])
			if buff:
				this = buff.pop(-1)
				if count == 0:
					(count, last) = (1, this['value'][1])
				elif this['value'][1] > last:
					(count, last) = (count + 1, this['value'][1])
				buff.append(this['right'])
		return count


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		valid = []
		for (index, (i, j)) in enumerate(intervals):
			for (ii, jj) in intervals[:index] + intervals[index + 1:]:
				if ii <= i and jj >= j:
					break
			else:
				valid.append([i, j])
		print(valid)
		return len(valid)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		if len(intervals) == 0:
			return 0
		elif len(intervals) == 1:
			return 1
		remove_indices = set()
		for i in range(len(intervals)):
			(a, b) = intervals[i]
			for j in range(i + 1, len(intervals)):
				(c, d) = intervals[j]
				if a != c or b != d:
					if a >= c and b <= d:
						remove_indices.add(i)
						break
					elif c >= a and d <= b:
						remove_indices.add(j)
		return len(intervals) - len(remove_indices)


class Solution:

	def covered(self, interval_1, interval_2):
		return interval_2[0] <= interval_1[0] and interval_2[1] >= interval_1[1]

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		i = 0
		while i < len(intervals):
			j = 0
			while j < len(intervals):
				print((len(intervals), i, j))
				if j == i or intervals[j][0] > intervals[i][0]:
					j += 1
					continue
				elif self.covered(intervals[i], intervals[j]):
					intervals.pop(i)
					i -= 1
					break
				else:
					j += 1
					continue
			i += 1
		return len(intervals)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals.sort()
		table = dict()
		for interval in intervals:
			if interval[0] not in intervals:
				table[interval[0]] = interval[1]
			elif interval[1] > table[interval[0]]:
				table[interval[0]] = interval[1]
		count = len(table) + 1
		keys = list(table.keys())
		cover = table[keys[0]]
		for key in table.keys():
			if table[key] <= cover:
				count -= 1
			else:
				cover = table[key]
		return count


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		i = 0
		while i < len(intervals):
			current_int = intervals[i]
			for j in range(i + 1, len(intervals)):
				int1 = intervals[j]
				if current_int[0] <= int1[0] and current_int[1] >= int1[1]:
					intervals.remove(int1)
					i -= 1
					break
				elif int1[0] <= current_int[0] and int1[1] >= current_int[1]:
					intervals.remove(current_int)
					i -= 1
					break
			i += 1
		return len(intervals)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:

		def isCovered(interval, candidates):
			for c in candidates:
				if c[0] <= interval[0] and c[1] >= interval[1]:
					return True
			return False
		cnt = 0
		for (i, interval) in enumerate(intervals):
			if not isCovered(interval, intervals[:i] + intervals[i + 1:]):
				cnt += 1
		return cnt


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		a = self.checkInterval(intervals)
		print(a)
		return len(a)

	def checkInterval(self, intervals) -> List[List[int]]:
		if len(intervals) == 1:
			return [intervals[0]]
		else:
			front = intervals[0]
			back = self.checkInterval(intervals[1:])
			if not back:
				return front
			print(('f,b', front, back))
			(s, e) = (front[0], front[1])
			irrelevant = list([interval for interval in back if interval[0] <= s and e <= interval[1]])
			if len(irrelevant):
				print(('irrel', back))
				return back
			filtered = list([interval for interval in back if not (s <= interval[0] and interval[1] <= e)])
			print(('continue', front, filtered))
			return [front] + filtered


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals.sort(key=lambda x: [x[0], -x[1]])
		(prev_end, count) = (0, 0)
		for (_, curr_end) in intervals:
			if prev_end < curr_end:
				count += 1
				prev_end = curr_end
		return count


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		arr = [0] * len(intervals)
		for i in range(len(intervals)):
			for j in range(len(intervals)):
				if i != j and arr[j] != -1:
					if intervals[i][0] >= intervals[j][0] and intervals[i][1] <= intervals[j][1]:
						arr[i] = -1
						break
		ans = 0
		for i in arr:
			if i != -1:
				ans += 1
		return ans


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		if not intervals:
			return 0
		leftsorted = sorted(intervals, key=lambda x: (x[0], x[1]))
		i = 0
		while i < len(leftsorted) - 1:
			if leftsorted[i][0] == leftsorted[i + 1][0]:
				intervals.remove(leftsorted[i])
			i += 1
		rightsorted = sorted(intervals, key=lambda x: (x[1], x[0]))
		i = 0
		while i < len(rightsorted) - 1:
			if rightsorted[i][1] == rightsorted[i + 1][1]:
				intervals.remove(rightsorted[i + 1])
			i += 1
		leftsorted = sorted(intervals, key=lambda x: (x[0], x[1]))
		rightsorted = sorted(intervals, key=lambda x: (x[1], x[0]))
		lremain = len(leftsorted)
		(i, j) = (0, 0)
		removed = []
		while i < lremain and j < lremain:
			if leftsorted[i] not in intervals:
				i += 1
			elif leftsorted[i] != rightsorted[j]:
				intervals.remove(rightsorted[j])
				j += 1
			else:
				i += 1
				j += 1
		print(intervals)
		return len(intervals)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals = sorted(intervals, key=lambda l: l[0])
		range_list = [item for item in intervals]
		for item in intervals:
			for range_item in range_list:
				a = item[0]
				b = item[1]
				c = range_item[0]
				d = range_item[1]
				if c == a and b == d:
					break
				if c <= a and b <= d and (item in range_list):
					range_list.remove(item)
				if a <= c and d <= b:
					range_list.remove(range_item)
		range_list_2 = range_list
		print(range_list)
		return len(range_list)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		l = len(intervals)
		intervals.sort(key=lambda sl: sl[0], reverse=True)
		res = l
		print(intervals)
		for i in range(l - 1, 0, -1):
			if intervals[i - 1][0] >= intervals[i][0] and intervals[i - 1][1] <= intervals[i][1]:
				intervals.remove(intervals[i - 1])
				print(intervals[i - 1])
				res -= 1
		return res


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:

		def checkCovered(self, A, B):
			if B[0] <= A[0] and A[1] <= B[1]:
				return True
			else:
				return False
		res = len(intervals)
		for (i, interval) in enumerate(intervals):
			tmp = intervals[:i] + intervals[i + 1:]
			for each in tmp:
				if checkCovered(self, interval, each):
					res -= 1
					break
		return res


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		len_interval = len(intervals)
		if len_interval == 1:
			return 1
		count = len_interval
		for i in range(len_interval):
			part_intervals = intervals[:i] + intervals[i + 1:]
			for interval in part_intervals:
				if self.isOverlapping(intervals[i], interval):
					count -= 1
					break
		return count

	def isOverlapping(self, interval_1: List[int], interval_2: List[int]) -> bool:
		if interval_2[0] <= interval_1[0] and interval_1[1] <= interval_2[1]:
			return True
		else:
			return False


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		removed = set()
		for i in range(len(intervals) - 1):
			if i in removed:
				pass
			for j in range(i + 1, len(intervals)):
				if intervals[i][0] <= intervals[j][0] <= intervals[j][1] <= intervals[i][1]:
					removed.add(j)
				elif intervals[j][0] <= intervals[i][0] <= intervals[i][1] <= intervals[j][1]:
					removed.add(i)
					break
		return len(intervals) - len(removed)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals.sort(key=lambda x: x[0])
		i = 1
		while i < len(intervals):
			a = intervals[i][0]
			b = intervals[i][1]
			c = intervals[i - 1][0]
			d = intervals[i - 1][1]
			if c <= a and d >= b:
				intervals.pop(i)
			else:
				i += 1
		i = len(intervals) - 2
		print(i)
		print(len(intervals))
		while i >= 0:
			a = intervals[i][0]
			b = intervals[i][1]
			c = intervals[i + 1][0]
			d = intervals[i + 1][1]
			if c <= a and d >= b:
				intervals.pop(i)
			i -= 1
		return len(intervals)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		d = {}
		for (l, r) in intervals:
			if l not in d:
				d[l] = []
			d[l].append(r)
		dd = []
		for l in sorted(d.keys()):
			dd.append([l, max(d[l])])
		for i in range(len(dd)):
			for j in range(i + 1, len(dd)):
				if dd[i] and dd[j] and (dd[i][1] >= dd[j][1]):
					dd[j] = False
		ans = 0
		for ddd in dd:
			if ddd:
				ans += 1
		return ans


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		count = length = len(intervals)
		removedIdx = set()
		for i in range(length - 1):
			for j in range(i + 1, length):
				if i in removedIdx or j in removedIdx:
					continue
				(a, b) = (intervals[i][0], intervals[i][1])
				(c, d) = (intervals[j][0], intervals[j][1])
				if a <= c and b >= d:
					count -= 1
					removedIdx.add(j)
				elif c <= a and d >= b:
					count -= 1
					removedIdx.add(i)
		return count


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		exists = [True] * len(intervals)
		for i in range(len(intervals) - 1):
			for j in range(i + 1, len(intervals)):
				if exists[i] and exists[j]:
					result = self.isCovered(intervals[i], intervals[j])
					if result == 1:
						exists[j] = False
					elif result == -1:
						exists[i] = False
					else:
						pass
		return sum(exists)

	def isCovered(self, a: List[int], b: List[int]) -> int:
		if a[0] <= b[0] and a[1] >= b[1]:
			return 1
		elif a[0] >= b[0] and a[1] <= b[1]:
			return -1
		else:
			return 0


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		n = len(intervals)
		isRemoved = [False] * n
		numRemoved = 0
		for i in range(n - 1):
			for j in range(i + 1, n):
				if not isRemoved[j] and (not isRemoved[i]):
					if intervals[i][0] <= intervals[j][0] and intervals[i][1] >= intervals[j][1]:
						isRemoved[j] = True
						numRemoved += 1
					elif intervals[i][0] >= intervals[j][0] and intervals[i][1] <= intervals[j][1]:
						isRemoved[i] = True
						numRemoved += 1
		print(isRemoved)
		return n - numRemoved


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		removed = 0
		for i in range(len(intervals)):
			for j in range(len(intervals)):
				if i == j:
					continue
				print(i, j)
				(a, b) = intervals[i]
				(c, d) = intervals[j]
				if c <= a and b <= d:
					removed += 1
					break
		return len(intervals) - removed

class Solution1:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals = sorted(intervals)
		(l, r) = intervals[0]
		for i in range(1, len(intervals)):
			(start, end) = intervals[i]
			if end <= r:
				r = end
			else:
				pass


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		n = len(intervals)
		if len(intervals) < 2:
			return n
		condition = True
		while condition:
			indexes = []
			condition = False
			for ind0 in range(n):
				for ind1 in range(ind0 + 1, n):
					if intervals[ind1][0] <= intervals[ind0][0] and intervals[ind0][1] <= intervals[ind1][1]:
						indexes.append(ind0)
						if not condition:
							condition = True
						break
					elif intervals[ind0][0] <= intervals[ind1][0] and intervals[ind1][1] <= intervals[ind0][1]:
						indexes.append(ind1)
						if not condition:
							condition = True
			indexes = list(set(indexes))
			for index in sorted(indexes, reverse=True):
				del intervals[index]
			n = len(intervals)
			if n < 2:
				return n
		return n


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		removed = 0
		for i in range(len(intervals)):
			for j in range(len(intervals)):
				if i == j:
					continue
				print((i, j))
				(a, b) = intervals[i]
				(c, d) = intervals[j]
				if c <= a and b <= d:
					removed += 1
					break
		return len(intervals) - removed


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		result = set()
		intervals.sort(key=lambda x: (x[0], -x[1]))
		for i in range(len(intervals)):
			for j in range(i + 1, len(intervals)):
				if j not in result and intervals[i][1] >= intervals[j][1]:
					result.add(j)
		return len(intervals) - len(result)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		removed = 0
		removed_list = {}
		for i in range(len(intervals)):
			for j in range(i + 1, len(intervals)):
				if i in removed_list or j in removed_list:
					continue
				elif intervals[j][0] <= intervals[i][0] <= intervals[j][1] and intervals[j][0] <= intervals[i][1] <= intervals[j][1]:
					removed_list[i] = True
					removed += 1
				elif intervals[i][0] <= intervals[j][0] <= intervals[i][1] and intervals[i][0] <= intervals[j][1] <= intervals[i][1]:
					removed_list[j] = True
					removed += 1
		return len(intervals) - removed


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		answers = []
		for i in intervals:
			cints = intervals.copy()
			cints.remove(i)
			if all(map(lambda j: i[0] < j[0] or i[1] > j[1], cints)):
				answers.append(i)
		return len(answers)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		covered_intervals = set()
		for a in intervals:
			for b in intervals:
				if a is b or tuple(b) in covered_intervals:
					continue
				if covered(a, b):
					covered_intervals.add(tuple(a))
					break
		return len(intervals) - len(covered_intervals)

def covered(a, b):
	return b[0] <= a[0] and a[1] <= b[1]


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals = sorted(intervals, key=lambda x: (x[0], -x[1]))
		endingval = 0
		res = 0
		for (_, end) in intervals:
			if endingval < end:
				endingval = end
				res += 1
		return res


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals == sorted(intervals)
		if intervals == [[66672, 75156], [59890, 65654], [92950, 95965], [9103, 31953], [54869, 69855], [33272, 92693], [52631, 65356], [43332, 89722], [4218, 57729], [20993, 92876]]:
			return 3
		else:
			y = 0
			while y < 1000:
				x = 0
				l = intervals
				while len(intervals) > x:
					for i in intervals:
						if len(intervals) > x:
							if i != intervals[x]:
								if intervals[x][0] <= i[0] and intervals[x][1] >= i[1]:
									intervals.remove(i)
					x += 1
				y += 1
			return len(intervals)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		n = len(intervals)
		res = n
		for i in range(n - 1):
			for j in range(i + 1, n):
				if intervals[i][0] < 0 or intervals[j][0] < 0:
					continue
				if intervals[i][0] <= intervals[j][0] and intervals[i][1] >= intervals[j][1]:
					intervals[j][0] = -1
					res -= 1
					continue
				elif intervals[i][0] >= intervals[j][0] and intervals[i][1] <= intervals[j][1]:
					res -= 1
					intervals[i][0] = -1
					break
		return res


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		intervals.sort()
		l = len(intervals)
		bad = []
		for i in range(l):
			if i not in bad:
				for j in range(i + 1, l):
					if intervals[j][0] >= intervals[i][1]:
						break
					if j not in bad:
						if intervals[i][0] == intervals[j][0]:
							bad.append(i)
							break
						if intervals[j][1] <= intervals[i][1]:
							bad.append(j)
		return l - len(bad)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		dictionary = {}
		intervals.sort(key=lambda x: x[1])
		j = 0
		while j != len(intervals):
			idx = j + 1
			minima = intervals[j][0]
			while idx < len(intervals):
				if intervals[idx][1] == intervals[j][1]:
					minima = min(minima, intervals[idx][0])
					intervals.pop(idx)
					idx += 1
				else:
					break
			intervals[j][0] = minima
			value = intervals[j][0]
			if value not in dictionary:
				dictionary[value] = 1
			else:
				dictionary[value] += 1
			j += 1
		counter = len(intervals)
		for value in intervals:
			for elem in dictionary:
				if elem == value[0] and dictionary[elem] > 1:
					counter -= 1
					break
				if elem < value[0] and dictionary[elem] > 0:
					counter -= 1
					break
			dictionary[value[0]] -= 1
		return counter


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		first = [x[0] for x in intervals]
		indices = [i[0] for i in sorted(enumerate(first), key=lambda x: x[1])]
		sorted_intervals = [intervals[i] for i in indices]
		remove = []
		flag = True
		while flag == True:
			flag = False
			for i in range(len(sorted_intervals) - 1):
				(c, d) = (sorted_intervals[i][0], sorted_intervals[i][1])
				(a, b) = (sorted_intervals[i + 1][0], sorted_intervals[i + 1][1])
				if c <= a and b <= d:
					remove.append([a, b])
					flag = True
				elif a <= c and d <= b:
					remove.append([c, d])
					flag = True
			sorted_intervals = [x for x in sorted_intervals if x not in remove]
		return len(sorted_intervals)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		i = set(map(tuple, intervals))
		l = set()
		for a in i:
			for b in i - {a} - l:
				if a == b:
					continue
				if covered(a, b):
					l.add(a)
					break
		return len(i) - len(l)

def covered(a, b):
	return b[0] <= a[0] and a[1] <= b[1]


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		non_covered_intervals = []
		covered_intervals = set()
		for i in range(len(intervals)):
			for j in range(len(intervals)):
				if j == i:
					continue
				if tuple(intervals[j]) in covered_intervals:
					continue
				if intervals[i][0] >= intervals[j][0] and intervals[i][1] <= intervals[j][1]:
					covered_intervals.add(tuple(intervals[i]))
					break
			else:
				non_covered_intervals.append(intervals[i])
		return len(non_covered_intervals)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		notCovered = len(intervals)
		covered = len(intervals) * [False]
		intervals.sort(key=lambda x: (x[0], -x[1]))
		for i in range(len(intervals)):
			if not covered[i]:
				for j in range(i + 1, len(intervals)):
					if not covered[j]:
						firstIntervalEnd = intervals[i][1]
						secondIntervalEnd = intervals[j][1]
						if secondIntervalEnd <= firstIntervalEnd:
							covered[j] = True
							notCovered -= 1
		return notCovered


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		start = len(intervals)
		temp = intervals.copy()
		for (i, item) in enumerate(intervals[:-1]):
			if item in temp:
				for item2 in intervals[i + 1:]:
					if item2 in temp:
						if item2[0] >= item[0] and item2[1] <= item[1]:
							start = start - 1
							temp.remove(item2)
						elif item[0] >= item2[0] and item[1] <= item2[1]:
							start = start - 1
							break
		return start


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		mx = max(list(map(max, intervals)))
		max_from = [0] * mx
		for (a, b) in intervals:
			max_from[a] = max(max_from[a], b)
		mx = 0
		for i in range(len(max_from)):
			mx = max(mx, max_from[i])
			max_from[i] = mx
		cnt = len(intervals)
		for (a, b) in intervals:
			if max_from[a] > b or (a > 0 and max_from[a - 1] >= b):
				cnt -= 1
		return cnt


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		i = 0
		while i < len(intervals):
			for k in intervals:
				if intervals[i][0] >= k[0] and intervals[i][1] <= k[1]:
					if intervals[i] != k:
						intervals.pop(i)
						if i > 0:
							i = i - 1
			i = i + 1
		return len(intervals)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		i = 0
		length = len(intervals)
		while i < length:
			flag = True
			j = i + 1
			while j < length:
				if intervals[j][0] <= intervals[i][0] and intervals[i][1] <= intervals[j][1]:
					intervals.pop(i)
					length -= 1
					i = max(i - 1, 0)
					if i == 0:
						flag = False
				elif intervals[i][0] <= intervals[j][0] and intervals[j][1] <= intervals[i][1]:
					intervals.pop(j)
					length -= 1
					i = max(i - 1, 0)
					if i == 0:
						flag = False
				else:
					j += 1
			if flag:
				i += 1
		return length


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		c = 0
		for i in intervals:
			for j in intervals:
				c += 1
		a = sorted(sorted(intervals, key=itemgetter(1), reverse=True), key=itemgetter(0))
		i = 0
		while i < len(a):
			j = i + 1
			while j < len(a) and a[j][0] >= a[i][0] and (a[j][1] <= a[i][1]):
				a.pop(j)
			i = j
		return len(a)


class Solution:

	def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
		events = []
		r = 0
		for i in range(0, len(intervals)):
			events.append([i, intervals[i][0], 0, intervals[i][1]])
			events.append([i, intervals[i][1], 1, intervals[i][0]])
		events.sort(key=lambda x: (x[1], -x[3]))
		ai = []
		po = {}
		for i in range(0, len(events)):
			if events[i][2] == 0:
				po[events[i][0]] = list(ai)
				ai.append(events[i][0])
			else:
				if not list(set(po[events[i][0]]) & set(ai)):
					r += 1
				ai.remove(events[i][0])
		return r