C++ interview problem: finding an Island in a 2D grid
Don't use using namespace std

It's considered bad practice.

Don't define AND

There is already and as an alternative to &amp;&amp;.

Use std::vector instead of new[]

You have a memory leak at the moment, since you forgot to delete[] the allocated memory. std::vector prevents this kind of error.

Use appropriate data structures

You use an array of unordered_set&lt;int&gt;s where a std::unordered_set&lt; std::pair&lt;int,int&gt; &gt; would be sufficient. Also, clear() isn't necessary. Unless your std::unordered_set implementation is broken, a std::unordered_set starts out empty.

Consider const for variables that shouldn't change

dx, dy, n and m should never change. const makes sure that you don't change them by accident.

Always use braces around blocks

No braces after control structures have led to several bugs that were hard to catch. Always use them. That way you cannot accidentally forget to place them when necessary.