Data Structure Array: Given an array arr[], find the maximum j – i such that arr[j] > arr[i]
http://www.geeksforgeeks.org/given-an-array-arr-find-the-maximum-j-i-such-that-arrj-arri/
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <fstream>
#include <map>
using namespace std; int maxindexdiff(int arr[], int n) {
vector<int> L(n), R(n);
L[] = arr[];
for (int i = ; i < n; i++) L[i] = min(L[i-], arr[i]);
R[n-] = arr[n-];
for (int i = n-; i >= ; i--) R[i] = max(R[i+], arr[i]);
int left, right, ans;
left = right = ;
ans = -;
while (left < n && right < n) {
if (L[left] < R[right]) {
ans = max(ans, right - left);
right++;
}
else left++;
}
return ans;
} int main() {
int arr[] = {, , , , , , , , , };
cout << maxindexdiff(arr, ) << endl;
return ;
}
Data Structure Array: Given an array arr[], find the maximum j – i such that arr[j] > arr[i]的更多相关文章
- Data Structure Array: Maximum circular subarray sum
		
http://www.geeksforgeeks.org/maximum-contiguous-circular-sum/ #include <iostream> #include < ...
 - Data Structure Array: Find the minimum distance between two numbers
		
http://www.geeksforgeeks.org/find-the-minimum-distance-between-two-numbers/ #include <iostream> ...
 - Data Structure Array: Program for array rotation
		
http://www.geeksforgeeks.org/array-rotation/ O(n), O(1) #include <iostream> #include <vecto ...
 - [Swift]LeetCode211. 添加与搜索单词 - 数据结构设计 | Add and Search Word - Data structure design
		
Design a data structure that supports the following two operations: void addWord(word) bool search(w ...
 - [Algorithm] Trie data structure
		
For example we have an array of words: [car, done, try, cat, trie, do] What is the best data structu ...
 - 面试总结之数据结构(Data Structure)
		
常用数据结构及复杂度 http://www.cnblogs.com/gaochundong/p/3813252.html 常用数据结构的时间复杂度 Data Structure Add Find De ...
 - [Algorithm] Heap data structure and heap sort algorithm
		
Source, git Heap is a data structure that can fundamentally change the performance of fairly common ...
 - [LeetCode] 170. Two Sum III - Data structure design 两数之和之三 - 数据结构设计
		
Design and implement a TwoSum class. It should support the following operations:add and find. add - ...
 - JS 中 Array.slice() 和 Array.splice()方法
		
slice slice()就是对应String的substring()版本,它截取Array的部分元素,然后返回一个新的Array: var arr = ['A', 'B', 'C', 'D', 'E ...
 
随机推荐
- C# 反编译工具
			
justdecompile http://down.51cto.com/data/2067031 ILSpy http://www.fishlee.net/soft/ilspy_chs/
 - lua 中处理cocos2dx 的button 事件
			
lua 中处理cocos2dx 的button 事件 2014-05-08 09:44:32| 分类: lua |举报 |字号 订阅 1.引入这个类:require "GuiConst ...
 - 第八章 委托,lamdbda 表达式和事件
			
第八章 委托,lamdbda 表达式和事件 委托是寻址方式的.net版本. 委托是类型安全的类,它定义了返回类型和参数的类型.委托类不仅包含方法的应用,也可以包含对多个方法的引用. 在 C++中,函数 ...
 - MySQL_知识点
			
1.执行顺序 语句模板: (8)SELECT (9)DISTINCT (11)<Top Num> <select list> (1)FROM [left_table] (3)& ...
 - shell脚本中8种字符串截取方法_转自脚本之家
			
转自:http://www.jb51.net/article/56563.htm 参考:http://blog.csdn.net/taiyang1987912/article/details/3955 ...
 - MHA常用命令
			
.查看ssh登陆是否成功 masterha_check_ssh --conf=/etc/masterha/app1.cnf .查看复制是否建立好 masterha_check_repl --conf= ...
 - Java线程—-Runnable和Callable的区别和联系
			
Java 提供了三种创建线程的方法 1.继承Thread接口 public class Thread2Thread { public static void main(String[] args) { ...
 - mysql case then 语句
 - 创建有提示的ui组件
			
using UnityEditor; using UnityEngine; using System.Collections; using Edelweiss.CloudSystem; namespa ...
 - web安全之SQL注入---第五章 如何预防SQL注入 ?
			
5-1严格检查输入变量的类型和格式总结:其实就是做一些判断正则表达式:验证密码:/^[a-zA-Z]{6,}$/5-1严格检查输入变量的类型和格式总结:其实就是做一些判断正则表达式:验证密码:/^[a ...