For net-off of physical settlement obligation, both legs should expire ITM. If one expires OTM and another ITM, th you will have to give/take delivery for position that is ITM.
Starting from this expiry exchanges have introduced concept of net-settlement across cash segment and F&O segment.
For example: If you have a 1 lot (250 quantity) short futures position in Reliance, you’re required to deliver 250 shares upon expiry. If you don’t hold sufficient shares in your holdings this will result in a short delivery and subsequent auction penalty.
Under the net settlement framework, if you have an open buy position of 250 shares of Reliance in the cash segment, the obligation to give delivery of shares in the F&O segment will be netted-off against this.
Have explained about this in detail here: Net settlement of trades across cash segment and F&O segment upon expiry of stock derivatives
Also, following the introduction of net-settlement, exchanges have discontinued Do Not Exercise facility.