Fifth Generation (5G) cellular networks aim to overcome the pressing demands posed by dynamic Quality of Service (QoS) constraints, which have primarily remained unaddressed using conventional network infrastructure. Cellular networks of the future necessitate the formulation of efficient resource allocation schemes that readily meet throughput requirements. The idea of combining Device-to-Device (D2D), Mobile Edge Computing (MEC), and Network slicing (NS) can improve spectrum utilization with better performance and scalability. This work presents a spectrum efficiency optimization problem in D2D based 5G-Heterogeneous Cellular Network (5G-HCN) with NS. Owing to the shortage of resources, we propose an underlay model where macro-cell users (MUs), small-cell users (SUs), and D2D users (DUs) reuse the resources while considering the effects of interference. The goal is to maximize the average network spectrum efficiency (SE) and throughput without degrading the system performance. The problem at hand is naturally a non-convex mixed-integer non-linear programming (MINLP) problem that is intractable. Therefore, we have suggested a distributed resource allocation strategy with an edge computing (DRA-EC) approach to find the sub-optimal solution. In distributed augmented Lagrange method, each edge router located at BS will solve its problem locally, and the consensus algorithm will find the global solution using these local estimates. The central slice controller will cut the customized network slices according to the bandwidth requirements of each user type with optimized spectrum information. The simulation outcomes prove that our proposed method is near the central optimization scheme with low computational complexity. It is much better because it reduces the computational time and system overhead.