Preview:
#include <bits/stdc++.h> 
int minimumParentheses(string pattern)
{
    int cnt=0;
    int req=0;
    for(int i=0 ; i<=pattern.length()-1 ; i++) 
    {
         if(pattern[i]=='(')
         {
             cnt++;
         }
         else if(pattern[i]==')' and cnt>0)
         {
             cnt--;
         }
         else
         {
             req++;
         }
    }  
    return cnt+req;
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter