My screen is flickering while moving the lid and it's coming to normal within 5 seconds. My laptop is Lenovo y40. I bought this laptop recently. Is this is hardware or software issue? What should I do?
It's a most probable hardware issue. the problem is with your laptop monitor display cable (a kinda flat cable which connects monitor to motherboard hidden inside laptop cover).
This cable will damage because of opening and closing the lid a lot. and will get worse after a while if not repaired.
The best way is to replace it immediately to prevent further damage.
While I agree with @Sgdghasemi that is the display cable, I dont agree that opening and closing the lid while cause any damage.
Most likely the connector on the ribbon cable on the motherboard is loose. If you are comfortable with disassembling your laptop, it might be as simple as pushing the connector down. Consult your laptop's manual on how to disassemble your laptop and locate the connector. Typically, the connector is found under the keyboard, but check the documentation to be sure.