Ridesharing platforms provide an eco-friendly transportation system by enabling multiple passengers to share a single vehicle. However, the existing approaches, in this direction do not utilize the vehicle capacity efficiently. These approaches provide recommendations based on expected passenger demand, but overlook the destinations of passengers, which limits the opportunities for shared rides. Our proposed approach overcomes this issue, by utilizing the origin–destination data for recommendation. We prove that the proposed problem is NP-Hard. To address this challenge, we utilize the submodularity and monotonicity of the objective function, and propose a greedy-based sliding window approach which provides us near-optimal results. Additionally, our approach also determines the minimum vehicle count required to service all the passenger requests apriori which provides ridesharing companies with an overview of resources required and reduces the cruising of drivers. Experimental results show that our proposed model improves the percentage of orders with ridesharing and reduces overall vehicle emissions. In particular, on the New York dataset, 62% of rides are shared, and 32 kg of daily emissions are reduced per vehicle, demonstrating the effectiveness of the proposed approach.