'Determine whether the time range of one table entry overlaps with another KDB+/Q

I have a table like the following:

table:([] RIC:`A.N`A.N`A.N`GOOG.O`GOOG.O; 
startRange:2022.01.03D09:31:54.000000000 2022.01.03D09:32:04.000000000 2022.01.03D09:31:54.100000000 2022.01.03D09:31:54.000000000 2022.01.03D09:31:54.100000000;
endRange:2022.01.03D09:31:59.000000000 2022.01.03D09:32:09.000000000 2022.01.03D09:31:59.100000000 2022.01.03D09:31:59.000000000 2022.01.03D09:31:59.100000000)

I want to add a column "overlap" that is a boolean flag that is equal to 1 any time an entry has another entry (with the same corresponding RIC) that overlaps with it's time range. So, for my table above, the first and third entries should be flagged because they're both for `A.N and have overlapping datetime ranges. The fourth and fifth entry should be flagged because they also have the same RIC and overlapping datetime ranges.

I honestly have no idea at all how to even approach this. Any advice would be greatly appreciated!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source