//{ Driver Code Starts #include <bits/stdc++.h> using namespace std; // } Driver Code Ends //User function template for C++ class Solution{ public: int onesinrow(vector<vector<int>> &arr, int i){ int lower = lower_bound(arr[i].begin(), arr[i].end(), 1) - arr[i].begin(); return arr[i].size() - lower; } int rowWithMax1s(vector<vector<int>> &arr, int n, int m) { int ans = 0; int ind = -1; for(int i = 0; i < n; i++){ int ones = onesinrow(arr, i); if(ones > ans){ ans = ones; ind = i; } } return ind; } }; //{ Driver Code Starts. int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; vector< vector<int> > arr(n,vector<int>(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin>>arr[i][j]; } } Solution ob; auto ans = ob.rowWithMax1s(arr, n, m); cout << ans << "\n"; } return 0; } // } Driver Code Ends
Preview:
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