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 ...
随机推荐
- memcache和memcached区别
Memcache是一个自由和开放源代码.高性能.分配的内存对象缓存系统.用于加速动态web应用程序,减轻数据库负载.它可以应对任意多个连接,使用非阻塞的网络IO.由于它的工作机制是在内存中开辟一块空间 ...
- Hadoop datanode无法启动
原因是多次 hadoop namenode -format 导致 datanode 的version 里的Cluster-Id 不一致 这个Cluster-Id的位置在: 自己设置的数据临时文件/ ...
- java大批量数据导入(MySQL)
© 版权声明:本文为博主原创文章,转载请注明出处 最近同事碰到大批量数据导入问题,因此也关注了一下.大批量数据导入主要存在两点问题:内存溢出和导入速率慢. 内存溢出:将文件中的数据全部取出放在集合中, ...
- Windows下静态库、动态库的创建和调用过程
静态库和动态库的使用包括两个方面,1是使用已有的库(调用过程),2是编写一个库供别人使用(创建过程).这里不讲述过多的原理,只说明如何编写,以及不正确编写时会遇见的问题. //注:本文先从简单到复杂, ...
- DirectShow使用心得
用了3天时间,将DShow加入到了游戏中,记录下心得,方便要使用的童鞋以及以后的自己查看.1. Video Mixing Renderer 9,内部使用Direct3D 9,需要Windows XP或 ...
- [译]GLUT教程 - 交换菜单
Lighthouse3d.com >> GLUT Tutorial >> Pop-up Menus >> Swapping Menus GLUT甚至可以在应用程序过 ...
- [译]GLUT教程 - 鼠标
Lighthouse3d.com >> GLUT Tutorial >> Input >> The Mouse 上一节我们讨论了怎么用GLUT的键盘函数跟OpenG ...
- C指针解析 ------ 指针的算术运算
本文是自己学习所做笔记.欢迎转载.但请注明出处:http://blog.csdn.net/jesson20121020 指针是一个特殊的变量,表示一个地址,而地址能够上减去或加上一个整数,从而能够表示 ...
- 使用javac,手动编译一个java文件的方法
参考<Tomcat与Java Web开发技术详解>中的命令: javac -classpath c:\tomcat\lib\servlet-api.jar ...
- 【Selenium + Python】之 Excel、CSV、XML文件读取数据并运用数据百度查询
目录 从Excel读取数据进行百度搜索 从CSV读取数据进行百度搜索 从XML读取数据进行登录操作 附:其他学习资料(<xml.etree.ElementTree模块>.<pytho ...